Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers.utils import load_image
|
| 3 |
+
from diffusers import FluxControlNetModel
|
| 4 |
+
from diffusers.pipelines import FluxControlNetPipeline
|
| 5 |
+
|
| 6 |
+
# Load pipeline
|
| 7 |
+
controlnet = FluxControlNetModel.from_pretrained(
|
| 8 |
+
"jasperai/Flux.1-dev-Controlnet-Upscaler",
|
| 9 |
+
torch_dtype=torch.bfloat16
|
| 10 |
+
)
|
| 11 |
+
pipe = FluxControlNetPipeline.from_pretrained(
|
| 12 |
+
"black-forest-labs/FLUX.1-dev",
|
| 13 |
+
controlnet=controlnet,
|
| 14 |
+
torch_dtype=torch.bfloat16
|
| 15 |
+
)
|
| 16 |
+
pipe.to("cuda")
|
| 17 |
+
|
| 18 |
+
# Load a control image
|
| 19 |
+
|
| 20 |
+
uploaded_file = st.file_uploader("Choose an image", type=["png", "jpg"])
|
| 21 |
+
|
| 22 |
+
control_image = None;
|
| 23 |
+
if uploaded_file is not None:
|
| 24 |
+
bytes_data = uploaded_file.getvalue
|
| 25 |
+
control_image = bytes_data
|
| 26 |
+
st.write(f"filename: {uploaded_file.name}")
|
| 27 |
+
st.image(bytes_data)
|
| 28 |
+
|
| 29 |
+
w, h = control_image.size
|
| 30 |
+
|
| 31 |
+
# Upscale x4
|
| 32 |
+
control_image = control_image.resize((w * 4, h * 4))
|
| 33 |
+
|
| 34 |
+
image = pipe(
|
| 35 |
+
prompt="",
|
| 36 |
+
control_image=control_image,
|
| 37 |
+
controlnet_conditioning_scale=0.6,
|
| 38 |
+
num_inference_steps=28,
|
| 39 |
+
guidance_scale=3.5,
|
| 40 |
+
height=control_image.size[1],
|
| 41 |
+
width=control_image.size[0]
|
| 42 |
+
).images[0]
|
| 43 |
+
st.image(image)
|