Upload 3 files
Browse files- README.md +13 -13
- app.py +337 -336
- requirements.txt +12 -10
README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: FLUX.1 [Inpainting with lora]
|
| 3 |
-
emoji: 🎨
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: pink
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 4.40.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: FLUX.1 [Inpainting with lora]
|
| 3 |
+
emoji: 🎨
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.40.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -1,336 +1,337 @@
|
|
| 1 |
-
from typing import Tuple
|
| 2 |
-
|
| 3 |
-
import requests
|
| 4 |
-
import random
|
| 5 |
-
import numpy as np
|
| 6 |
-
import gradio as gr
|
| 7 |
-
import spaces
|
| 8 |
-
import torch
|
| 9 |
-
from PIL import Image
|
| 10 |
-
from diffusers import FluxInpaintPipeline
|
| 11 |
-
from huggingface_hub import login
|
| 12 |
-
import os
|
| 13 |
-
import time
|
| 14 |
-
from gradio_imageslider import ImageSlider
|
| 15 |
-
|
| 16 |
-
from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
|
| 17 |
-
from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
|
| 18 |
-
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
| 19 |
-
import requests
|
| 20 |
-
from io import BytesIO
|
| 21 |
-
import PIL.Image
|
| 22 |
-
import requests
|
| 23 |
-
|
| 24 |
-
MARKDOWN = """
|
| 25 |
-
# FLUX.1 Inpainting with lora
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 29 |
-
IMAGE_SIZE = 1024
|
| 30 |
-
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 31 |
-
HF_TOKEN =
|
| 32 |
-
|
| 33 |
-
#login(token=HF_TOKEN)
|
| 34 |
-
|
| 35 |
-
bfl_repo="black-forest-labs/FLUX.1-dev"
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
self.
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
self.
|
| 50 |
-
self.
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
#
|
| 76 |
-
#
|
| 77 |
-
#
|
| 78 |
-
#
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
#
|
| 93 |
-
#
|
| 94 |
-
#
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
image
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
response.
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
response.
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
"
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
|
|
|
|
|
| 1 |
+
from typing import Tuple
|
| 2 |
+
|
| 3 |
+
import requests
|
| 4 |
+
import random
|
| 5 |
+
import numpy as np
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import spaces
|
| 8 |
+
import torch
|
| 9 |
+
from PIL import Image
|
| 10 |
+
from diffusers import FluxInpaintPipeline
|
| 11 |
+
from huggingface_hub import login
|
| 12 |
+
import os
|
| 13 |
+
import time
|
| 14 |
+
from gradio_imageslider import ImageSlider
|
| 15 |
+
|
| 16 |
+
from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
|
| 17 |
+
from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
|
| 18 |
+
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
| 19 |
+
import requests
|
| 20 |
+
from io import BytesIO
|
| 21 |
+
import PIL.Image
|
| 22 |
+
import requests
|
| 23 |
+
|
| 24 |
+
MARKDOWN = """
|
| 25 |
+
# FLUX.1 Inpainting with lora
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 29 |
+
IMAGE_SIZE = 1024
|
| 30 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 31 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 32 |
+
|
| 33 |
+
#login(token=HF_TOKEN)
|
| 34 |
+
|
| 35 |
+
#bfl_repo="black-forest-labs/FLUX.1-dev"
|
| 36 |
+
bfl_repo="camenduru/FLUX.1-dev-diffusers"
|
| 37 |
+
|
| 38 |
+
class calculateDuration:
|
| 39 |
+
def __init__(self, activity_name=""):
|
| 40 |
+
self.activity_name = activity_name
|
| 41 |
+
|
| 42 |
+
def __enter__(self):
|
| 43 |
+
self.start_time = time.time()
|
| 44 |
+
self.start_time_formatted = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.start_time))
|
| 45 |
+
print(f"Activity: {self.activity_name}, Start time: {self.start_time_formatted}")
|
| 46 |
+
return self
|
| 47 |
+
|
| 48 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 49 |
+
self.end_time = time.time()
|
| 50 |
+
self.elapsed_time = self.end_time - self.start_time
|
| 51 |
+
self.end_time_formatted = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.end_time))
|
| 52 |
+
|
| 53 |
+
if self.activity_name:
|
| 54 |
+
print(f"Elapsed time for {self.activity_name}: {self.elapsed_time:.6f} seconds")
|
| 55 |
+
else:
|
| 56 |
+
print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
|
| 57 |
+
|
| 58 |
+
print(f"Activity: {self.activity_name}, End time: {self.start_time_formatted}")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def remove_background(image: Image.Image, threshold: int = 50) -> Image.Image:
|
| 62 |
+
image = image.convert("RGBA")
|
| 63 |
+
data = image.getdata()
|
| 64 |
+
new_data = []
|
| 65 |
+
for item in data:
|
| 66 |
+
avg = sum(item[:3]) / 3
|
| 67 |
+
if avg < threshold:
|
| 68 |
+
new_data.append((0, 0, 0, 0))
|
| 69 |
+
else:
|
| 70 |
+
new_data.append(item)
|
| 71 |
+
|
| 72 |
+
image.putdata(new_data)
|
| 73 |
+
return image
|
| 74 |
+
|
| 75 |
+
# text_encoder = CLIPTextModel.from_pretrained(os.path.join(os.getcwd(), "flux_text_encoders/clip_l.safetensors"), torch_dtype=dtype)
|
| 76 |
+
# tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=dtype)
|
| 77 |
+
# text_encoder_2 = T5EncoderModel.from_pretrained(os.path.join(os.getcwd(), "flux_text_encoders/t5xxl_fp8_e4m3fn.safetensors"), torch_dtype=dtype)
|
| 78 |
+
# tokenizer_2 = T5TokenizerFast.from_pretrained(bfl_repo, subfolder="tokenizer_2", torch_dtype=dtype)
|
| 79 |
+
# vae = AutoencoderKL.from_pretrained(bfl_repo, subfolder="vae", torch_dtype=dtype)
|
| 80 |
+
# transformer = FluxTransformer2DModel.from_pretrained(bfl_repo, subfolder="transformer", torch_dtype=dtype)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
pipe = FluxInpaintPipeline.from_pretrained(bfl_repo, torch_dtype=torch.bfloat16).to(DEVICE)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def resize_image_dimensions(
|
| 87 |
+
original_resolution_wh: Tuple[int, int],
|
| 88 |
+
maximum_dimension: int = IMAGE_SIZE
|
| 89 |
+
) -> Tuple[int, int]:
|
| 90 |
+
width, height = original_resolution_wh
|
| 91 |
+
|
| 92 |
+
# if width <= maximum_dimension and height <= maximum_dimension:
|
| 93 |
+
# width = width - (width % 32)
|
| 94 |
+
# height = height - (height % 32)
|
| 95 |
+
# return width, height
|
| 96 |
+
|
| 97 |
+
if width > height:
|
| 98 |
+
scaling_factor = maximum_dimension / width
|
| 99 |
+
else:
|
| 100 |
+
scaling_factor = maximum_dimension / height
|
| 101 |
+
|
| 102 |
+
new_width = int(width * scaling_factor)
|
| 103 |
+
new_height = int(height * scaling_factor)
|
| 104 |
+
|
| 105 |
+
new_width = new_width - (new_width % 32)
|
| 106 |
+
new_height = new_height - (new_height % 32)
|
| 107 |
+
|
| 108 |
+
return new_width, new_height
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
@spaces.GPU(duration=100)
|
| 112 |
+
def process(
|
| 113 |
+
input_image_editor: dict,
|
| 114 |
+
image_url: str,
|
| 115 |
+
mask_url: str,
|
| 116 |
+
blur_mask: bool,
|
| 117 |
+
blur_factor: int,
|
| 118 |
+
lora_path: str,
|
| 119 |
+
lora_weights: str,
|
| 120 |
+
lora_scale: float,
|
| 121 |
+
trigger_word: str,
|
| 122 |
+
input_text: str,
|
| 123 |
+
seed_slicer: int,
|
| 124 |
+
randomize_seed_checkbox: bool,
|
| 125 |
+
strength_slider: float,
|
| 126 |
+
num_inference_steps_slider: int,
|
| 127 |
+
progress=gr.Progress(track_tqdm=True)
|
| 128 |
+
):
|
| 129 |
+
if not input_text:
|
| 130 |
+
gr.Info("Please enter a text prompt.")
|
| 131 |
+
return None, None
|
| 132 |
+
|
| 133 |
+
# default image edtiro
|
| 134 |
+
image = input_image_editor['background']
|
| 135 |
+
mask = input_image_editor['layers'][0]
|
| 136 |
+
|
| 137 |
+
if image_url:
|
| 138 |
+
print("start to fetch image from url", image_url)
|
| 139 |
+
response = requests.get(image_url)
|
| 140 |
+
response.raise_for_status()
|
| 141 |
+
image = PIL.Image.open(BytesIO(response.content))
|
| 142 |
+
print("fetch image success")
|
| 143 |
+
|
| 144 |
+
if mask_url:
|
| 145 |
+
print("start to fetch mask from url", mask_url)
|
| 146 |
+
response = requests.get(mask_url)
|
| 147 |
+
response.raise_for_status()
|
| 148 |
+
mask = PIL.Image.open(BytesIO(response.content))
|
| 149 |
+
print("fetch mask success")
|
| 150 |
+
|
| 151 |
+
if not image:
|
| 152 |
+
gr.Info("Please upload an image.")
|
| 153 |
+
return None, None
|
| 154 |
+
|
| 155 |
+
if not mask:
|
| 156 |
+
gr.Info("Please draw a mask on the image.")
|
| 157 |
+
return None, None
|
| 158 |
+
if blur_mask:
|
| 159 |
+
mask = pipe.mask_processor.blur(mask, blur_factor=blur_factor)
|
| 160 |
+
|
| 161 |
+
with calculateDuration("resize image"):
|
| 162 |
+
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
| 163 |
+
resized_image = image.resize((width, height), Image.LANCZOS)
|
| 164 |
+
resized_mask = mask.resize((width, height), Image.LANCZOS)
|
| 165 |
+
|
| 166 |
+
with calculateDuration("load lora"):
|
| 167 |
+
print(lora_path, lora_weights)
|
| 168 |
+
pipe.load_lora_weights(lora_path, weight_name=lora_weights)
|
| 169 |
+
|
| 170 |
+
if randomize_seed_checkbox:
|
| 171 |
+
seed_slicer = random.randint(0, MAX_SEED)
|
| 172 |
+
generator = torch.Generator().manual_seed(seed_slicer)
|
| 173 |
+
|
| 174 |
+
with calculateDuration("run pipe"):
|
| 175 |
+
print(input_text, width, height, strength_slider, num_inference_steps_slider, lora_scale)
|
| 176 |
+
result = pipe(
|
| 177 |
+
prompt=f"{input_text} {trigger_word}",
|
| 178 |
+
image=resized_image,
|
| 179 |
+
mask_image=resized_mask,
|
| 180 |
+
width=width,
|
| 181 |
+
height=height,
|
| 182 |
+
strength=strength_slider,
|
| 183 |
+
generator=generator,
|
| 184 |
+
num_inference_steps=num_inference_steps_slider,
|
| 185 |
+
max_sequence_length=256,
|
| 186 |
+
joint_attention_kwargs={"scale": lora_scale},
|
| 187 |
+
).images[0]
|
| 188 |
+
|
| 189 |
+
return [resized_image, result], resized_mask
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
with gr.Blocks() as demo:
|
| 193 |
+
gr.Markdown(MARKDOWN)
|
| 194 |
+
with gr.Row():
|
| 195 |
+
with gr.Column():
|
| 196 |
+
input_image_editor_component = gr.ImageEditor(
|
| 197 |
+
label='Image',
|
| 198 |
+
type='pil',
|
| 199 |
+
sources=["upload", "webcam"],
|
| 200 |
+
image_mode='RGB',
|
| 201 |
+
layers=False,
|
| 202 |
+
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
|
| 203 |
+
|
| 204 |
+
image_url = gr.Textbox(
|
| 205 |
+
label="image url",
|
| 206 |
+
show_label=True,
|
| 207 |
+
max_lines=1,
|
| 208 |
+
placeholder="Enter your image url (Optional)",
|
| 209 |
+
)
|
| 210 |
+
mask_url = gr.Textbox(
|
| 211 |
+
label="Mask image url",
|
| 212 |
+
show_label=True,
|
| 213 |
+
max_lines=1,
|
| 214 |
+
placeholder="Enter your mask image url (Optional)",
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
with gr.Accordion("Prompt Settings", open=True):
|
| 218 |
+
|
| 219 |
+
input_text_component = gr.Textbox(
|
| 220 |
+
label="Inpaint prompt",
|
| 221 |
+
show_label=True,
|
| 222 |
+
max_lines=1,
|
| 223 |
+
placeholder="Enter your prompt",
|
| 224 |
+
)
|
| 225 |
+
trigger_word = gr.Textbox(
|
| 226 |
+
label="Lora trigger word",
|
| 227 |
+
show_label=True,
|
| 228 |
+
max_lines=1,
|
| 229 |
+
placeholder="Enter your lora trigger word here",
|
| 230 |
+
value="a photo of TOK"
|
| 231 |
+
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
submit_button_component = gr.Button(
|
| 235 |
+
value='Submit', variant='primary', scale=0)
|
| 236 |
+
|
| 237 |
+
with gr.Accordion("Lora Settings", open=True):
|
| 238 |
+
lora_path = gr.Textbox(
|
| 239 |
+
label="Lora model path",
|
| 240 |
+
show_label=True,
|
| 241 |
+
max_lines=1,
|
| 242 |
+
placeholder="Enter your model path",
|
| 243 |
+
info="Currently, only LoRA hosted on Hugging Face'model can be loaded properly.",
|
| 244 |
+
value="XLabs-AI/flux-RealismLora"
|
| 245 |
+
)
|
| 246 |
+
lora_weights = gr.Textbox(
|
| 247 |
+
label="Lora weights",
|
| 248 |
+
show_label=True,
|
| 249 |
+
max_lines=1,
|
| 250 |
+
placeholder="Enter your lora weights name",
|
| 251 |
+
value="lora.safetensors"
|
| 252 |
+
)
|
| 253 |
+
lora_scale = gr.Slider(
|
| 254 |
+
label="Lora scale",
|
| 255 |
+
show_label=True,
|
| 256 |
+
minimum=0,
|
| 257 |
+
maximum=1,
|
| 258 |
+
step=0.1,
|
| 259 |
+
value=0.9,
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
with gr.Accordion("Advanced Settings", open=True):
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
seed_slicer_component = gr.Slider(
|
| 266 |
+
label="Seed",
|
| 267 |
+
minimum=0,
|
| 268 |
+
maximum=MAX_SEED,
|
| 269 |
+
step=1,
|
| 270 |
+
value=42,
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
randomize_seed_checkbox_component = gr.Checkbox(
|
| 274 |
+
label="Randomize seed", value=True)
|
| 275 |
+
|
| 276 |
+
blur_mask = gr.Checkbox(
|
| 277 |
+
label="if blur mask", value=False)
|
| 278 |
+
blur_factor = gr.Slider(
|
| 279 |
+
label="blur factor",
|
| 280 |
+
minimum=0,
|
| 281 |
+
maximum=50,
|
| 282 |
+
step=1,
|
| 283 |
+
value=33,
|
| 284 |
+
)
|
| 285 |
+
with gr.Row():
|
| 286 |
+
strength_slider_component = gr.Slider(
|
| 287 |
+
label="Strength",
|
| 288 |
+
info="Indicates extent to transform the reference `image`. "
|
| 289 |
+
"Must be between 0 and 1. `image` is used as a starting "
|
| 290 |
+
"point and more noise is added the higher the `strength`.",
|
| 291 |
+
minimum=0,
|
| 292 |
+
maximum=1,
|
| 293 |
+
step=0.01,
|
| 294 |
+
value=0.85,
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
num_inference_steps_slider_component = gr.Slider(
|
| 298 |
+
label="Number of inference steps",
|
| 299 |
+
info="The number of denoising steps. More denoising steps "
|
| 300 |
+
"usually lead to a higher quality image at the",
|
| 301 |
+
minimum=1,
|
| 302 |
+
maximum=50,
|
| 303 |
+
step=1,
|
| 304 |
+
value=28,
|
| 305 |
+
)
|
| 306 |
+
with gr.Column():
|
| 307 |
+
output_image_component = ImageSlider(label="Generate image", type="pil", slider_color="pink")
|
| 308 |
+
|
| 309 |
+
with gr.Accordion("Debug", open=False):
|
| 310 |
+
output_mask_component = gr.Image(
|
| 311 |
+
type='pil', image_mode='RGB', label='Input mask', format="png")
|
| 312 |
+
|
| 313 |
+
submit_button_component.click(
|
| 314 |
+
fn=process,
|
| 315 |
+
inputs=[
|
| 316 |
+
input_image_editor_component,
|
| 317 |
+
image_url,
|
| 318 |
+
mask_url,
|
| 319 |
+
blur_mask,
|
| 320 |
+
blur_factor,
|
| 321 |
+
lora_path,
|
| 322 |
+
lora_weights,
|
| 323 |
+
lora_scale,
|
| 324 |
+
trigger_word,
|
| 325 |
+
input_text_component,
|
| 326 |
+
seed_slicer_component,
|
| 327 |
+
randomize_seed_checkbox_component,
|
| 328 |
+
strength_slider_component,
|
| 329 |
+
num_inference_steps_slider_component
|
| 330 |
+
],
|
| 331 |
+
outputs=[
|
| 332 |
+
output_image_component,
|
| 333 |
+
output_mask_component
|
| 334 |
+
]
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
demo.launch(debug=False, show_error=True)
|
requirements.txt
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
spaces
|
| 3 |
-
accelerate
|
| 4 |
-
transformers==4.42.4
|
| 5 |
-
sentencepiece
|
| 6 |
-
git+https://github.com/Gothos/diffusers.git@flux-inpaint
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
spaces
|
| 3 |
+
accelerate
|
| 4 |
+
transformers==4.42.4
|
| 5 |
+
sentencepiece
|
| 6 |
+
#git+https://github.com/Gothos/diffusers.git@flux-inpaint
|
| 7 |
+
diffusers
|
| 8 |
+
huggingface_hub
|
| 9 |
+
peft
|
| 10 |
+
gradio_imageslider
|
| 11 |
+
requests
|
| 12 |
+
numpy<2
|