Spaces:
Running
on
Zero
Running
on
Zero
Create raw.py
Browse files
raw.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from diffusers.utils import load_image
|
3 |
+
from diffusers import FluxControlNetModel
|
4 |
+
from diffusers.pipelines import FluxControlNetPipeline
|
5 |
+
import spaces
|
6 |
+
|
7 |
+
# Load pipeline
|
8 |
+
controlnet = FluxControlNetModel.from_pretrained(
|
9 |
+
"jasperai/Flux.1-dev-Controlnet-Upscaler",
|
10 |
+
torch_dtype=torch.bfloat16
|
11 |
+
)
|
12 |
+
pipe = FluxControlNetPipeline.from_pretrained(
|
13 |
+
"black-forest-labs/FLUX.1-dev",
|
14 |
+
controlnet=controlnet,
|
15 |
+
torch_dtype=torch.bfloat16
|
16 |
+
)
|
17 |
+
pipe.to("cuda")
|
18 |
+
|
19 |
+
# Load a control image
|
20 |
+
control_image = load_image(
|
21 |
+
"https://img.getimg.ai/generated/img-HvTBfR1W1RUhykk7gmBUYp.png"
|
22 |
+
)
|
23 |
+
|
24 |
+
w, h = control_image.size
|
25 |
+
|
26 |
+
# Upscale x4
|
27 |
+
control_image = control_image.resize((w * 2, h * 2))
|
28 |
+
|
29 |
+
image = pipe(
|
30 |
+
prompt="",
|
31 |
+
control_image=control_image,
|
32 |
+
controlnet_conditioning_scale=0.6,
|
33 |
+
num_inference_steps=14,
|
34 |
+
guidance_scale=3.5,
|
35 |
+
height=control_image.size[1],
|
36 |
+
width=control_image.size[0]
|
37 |
+
).images[0]
|
38 |
+
image
|