Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from diffusers import AutoencoderKL, FluxTransformer2DModel
|
| 4 |
from diffusers.utils import load_image
|
| 5 |
from controlnet_flux import FluxControlNetModel
|
| 6 |
from transformer_flux import FluxTransformer2DModel
|
|
@@ -12,26 +12,13 @@ import spaces
|
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
from optimum.quanto import freeze, qfloat8, quantize
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
transformer = FluxTransformer2DModel.from_pretrained(
|
| 18 |
-
"black-forest-labs/FLUX.1-dev", subfolder='transformer', torch_dtype=torch.bfloat16
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
pipe = FluxControlNetInpaintingPipeline.from_pretrained(
|
| 22 |
-
"black-forest-labs/FLUX.1-dev",
|
| 23 |
-
transformer=transformer,
|
| 24 |
-
controlnet=controlnet,
|
| 25 |
torch_dtype=torch.bfloat16
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
repo_name = "ByteDance/Hyper-SD"
|
| 29 |
-
ckpt_name = "Hyper-FLUX.1-dev-8steps-lora.safetensors"
|
| 30 |
-
pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))
|
| 31 |
-
pipe.fuse_lora(lora_scale=0.125)
|
| 32 |
-
pipe.transformer.to(torch.bfloat16)
|
| 33 |
-
pipe.controlnet.to(torch.bfloat16)
|
| 34 |
pipe.to("cuda")
|
|
|
|
| 35 |
def can_expand(source_width, source_height, target_width, target_height, alignment):
|
| 36 |
if alignment in ("Left", "Right") and source_width >= target_width:
|
| 37 |
return False
|
|
@@ -147,7 +134,7 @@ def inpaint(image, width, height, overlap_percentage, num_inference_steps, resiz
|
|
| 147 |
cnet_image = background.copy()
|
| 148 |
cnet_image.paste(0, (0, 0), mask)
|
| 149 |
|
| 150 |
-
final_prompt =
|
| 151 |
|
| 152 |
#generator = torch.Generator(device="cuda").manual_seed(42)
|
| 153 |
|
|
@@ -155,14 +142,10 @@ def inpaint(image, width, height, overlap_percentage, num_inference_steps, resiz
|
|
| 155 |
prompt=final_prompt,
|
| 156 |
height=height,
|
| 157 |
width=width,
|
| 158 |
-
|
| 159 |
-
|
| 160 |
num_inference_steps=num_inference_steps,
|
| 161 |
-
|
| 162 |
-
controlnet_conditioning_scale=0.9,
|
| 163 |
-
guidance_scale=3.5,
|
| 164 |
-
negative_prompt="",
|
| 165 |
-
true_guidance_scale=3.5,
|
| 166 |
).images[0]
|
| 167 |
|
| 168 |
result = result.convert("RGBA")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from diffusers import AutoencoderKL, FluxTransformer2DModel, FluxFillPipeline
|
| 4 |
from diffusers.utils import load_image
|
| 5 |
from controlnet_flux import FluxControlNetModel
|
| 6 |
from transformer_flux import FluxTransformer2DModel
|
|
|
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
from optimum.quanto import freeze, qfloat8, quantize
|
| 14 |
|
| 15 |
+
pipe = FluxFillPipeline.from_pretrained(
|
| 16 |
+
"black-forest-labs/FLUX.1-Fill-dev",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
torch_dtype=torch.bfloat16
|
| 18 |
+
).to("cuda")
|
| 19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
pipe.to("cuda")
|
| 21 |
+
|
| 22 |
def can_expand(source_width, source_height, target_width, target_height, alignment):
|
| 23 |
if alignment in ("Left", "Right") and source_width >= target_width:
|
| 24 |
return False
|
|
|
|
| 134 |
cnet_image = background.copy()
|
| 135 |
cnet_image.paste(0, (0, 0), mask)
|
| 136 |
|
| 137 |
+
final_prompt = prompt_input
|
| 138 |
|
| 139 |
#generator = torch.Generator(device="cuda").manual_seed(42)
|
| 140 |
|
|
|
|
| 142 |
prompt=final_prompt,
|
| 143 |
height=height,
|
| 144 |
width=width,
|
| 145 |
+
image=cnet_image,
|
| 146 |
+
mask_image=mask,
|
| 147 |
num_inference_steps=num_inference_steps,
|
| 148 |
+
guidance_scale=30,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
).images[0]
|
| 150 |
|
| 151 |
result = result.convert("RGBA")
|