Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -103,6 +103,15 @@ def load_pipeline():
|
|
103 |
pipeline_loaded = True
|
104 |
return pipeline
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
@spaces.GPU(duration=120)
|
107 |
def style_transfer(input_image, style_name, prompt_suffix, num_inference_steps, guidance_scale, seed):
|
108 |
"""
|
@@ -181,10 +190,6 @@ def style_transfer(input_image, style_name, prompt_suffix, num_inference_steps,
|
|
181 |
torch.cuda.empty_cache()
|
182 |
return None
|
183 |
|
184 |
-
def select_style(style_name):
|
185 |
-
"""Handler for thumbnail clicks"""
|
186 |
-
return style_name, style_descriptions.get(style_name, "")
|
187 |
-
|
188 |
def create_thumbnail_grid():
|
189 |
"""Create a gallery of style thumbnails"""
|
190 |
thumbnails = []
|
@@ -209,18 +214,10 @@ def create_thumbnail_grid():
|
|
209 |
return thumbnails
|
210 |
|
211 |
# Create Gradio interface
|
212 |
-
with gr.Blocks(title="
|
213 |
-
gr.Markdown(""
|
214 |
-
# 🎨 FLUX.1 Kontext Style Transfer
|
215 |
-
|
216 |
-
Transform your images into various artistic styles using FLUX.1-Kontext-dev and high-quality style LoRAs.
|
217 |
-
|
218 |
-
This demo uses the official Owen777/Kontext-Style-Loras collection with 22 different artistic styles!
|
219 |
-
""")
|
220 |
|
221 |
# Thumbnail Grid Section
|
222 |
-
gr.Markdown("### 🖼️ Click a style thumbnail to select it:")
|
223 |
-
|
224 |
with gr.Row():
|
225 |
style_gallery = gr.Gallery(
|
226 |
value=create_thumbnail_grid(),
|
@@ -235,21 +232,19 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
235 |
show_download_button=False
|
236 |
)
|
237 |
|
238 |
-
gr.Markdown("---")
|
239 |
-
|
240 |
with gr.Row():
|
241 |
with gr.Column(scale=1):
|
242 |
input_image = gr.Image(
|
243 |
-
label="
|
244 |
type="pil",
|
245 |
-
height=400
|
|
|
246 |
)
|
247 |
|
248 |
style_dropdown = gr.Dropdown(
|
249 |
choices=list(style_type_lora_dict.keys()),
|
250 |
value="Ghibli",
|
251 |
label="Selected Style",
|
252 |
-
info="Choose from 22 different artistic styles or click a thumbnail above",
|
253 |
elem_id="style_dropdown"
|
254 |
)
|
255 |
|
@@ -262,7 +257,7 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
262 |
|
263 |
prompt_suffix = gr.Textbox(
|
264 |
label="Additional Instructions (Optional)",
|
265 |
-
placeholder="Add extra details
|
266 |
lines=2
|
267 |
)
|
268 |
|
@@ -272,8 +267,7 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
272 |
maximum=50,
|
273 |
value=24,
|
274 |
step=1,
|
275 |
-
label="Inference Steps"
|
276 |
-
info="More steps = better quality but slower"
|
277 |
)
|
278 |
|
279 |
guidance = gr.Slider(
|
@@ -281,15 +275,13 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
281 |
maximum=5.0,
|
282 |
value=2.5,
|
283 |
step=0.1,
|
284 |
-
label="Guidance Scale"
|
285 |
-
info="How closely to follow the prompt (2.5 recommended)"
|
286 |
)
|
287 |
|
288 |
seed = gr.Number(
|
289 |
label="Seed",
|
290 |
value=42,
|
291 |
-
precision=0
|
292 |
-
info="Set to 0 for random results"
|
293 |
)
|
294 |
|
295 |
generate_btn = gr.Button("🎨 Transform Image", variant="primary", size="lg")
|
@@ -300,16 +292,6 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
300 |
type="pil",
|
301 |
height=400
|
302 |
)
|
303 |
-
|
304 |
-
gr.Markdown("""
|
305 |
-
### 💡 Tips:
|
306 |
-
- Click any thumbnail above to quickly select a style
|
307 |
-
- All images are resized to 1024x1024
|
308 |
-
- First run downloads the model (~12GB)
|
309 |
-
- Each style transformation takes ~30-60 seconds
|
310 |
-
- Try different styles to find the best match!
|
311 |
-
- Use additional instructions for fine control
|
312 |
-
""")
|
313 |
|
314 |
# Handle gallery selection
|
315 |
def on_gallery_select(evt: gr.SelectData):
|
@@ -337,20 +319,6 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
337 |
outputs=[style_info]
|
338 |
)
|
339 |
|
340 |
-
# Examples
|
341 |
-
gr.Examples(
|
342 |
-
examples=[
|
343 |
-
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "Ghibli", ""],
|
344 |
-
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "3D_Chibi", "make it extra cute"],
|
345 |
-
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "Van_Gogh", "with swirling sky"],
|
346 |
-
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "Pixel", "8-bit retro game style"],
|
347 |
-
],
|
348 |
-
inputs=[input_image, style_dropdown, prompt_suffix],
|
349 |
-
outputs=output_image,
|
350 |
-
fn=style_transfer,
|
351 |
-
cache_examples=False
|
352 |
-
)
|
353 |
-
|
354 |
# Connect the generate button
|
355 |
generate_btn.click(
|
356 |
fn=style_transfer,
|
@@ -360,16 +328,6 @@ with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as
|
|
360 |
|
361 |
gr.Markdown("""
|
362 |
---
|
363 |
-
### 📚 Available Styles:
|
364 |
-
|
365 |
-
**Anime/Cartoon**: Ghibli, American Cartoon, Jojo, Snoopy, Rick & Morty, Irasutoya
|
366 |
-
**3D/Geometric**: 3D Chibi, Poly, LEGO, Clay Toy
|
367 |
-
**Traditional Art**: Chinese Ink, Oil Painting, Van Gogh, Picasso, Pop Art
|
368 |
-
**Craft/Material**: Fabric, Origami, Paper Cutting, Macaron
|
369 |
-
**Digital/Modern**: Pixel, Line, Vector
|
370 |
-
|
371 |
-
---
|
372 |
-
|
373 |
Powered by ❤️ https://discord.gg/openfreeai
|
374 |
""")
|
375 |
|
|
|
103 |
pipeline_loaded = True
|
104 |
return pipeline
|
105 |
|
106 |
+
def load_default_image():
|
107 |
+
"""Load the default man.webp image"""
|
108 |
+
if os.path.exists("man.webp"):
|
109 |
+
try:
|
110 |
+
return Image.open("man.webp")
|
111 |
+
except Exception as e:
|
112 |
+
print(f"Error loading default image: {e}")
|
113 |
+
return None
|
114 |
+
|
115 |
@spaces.GPU(duration=120)
|
116 |
def style_transfer(input_image, style_name, prompt_suffix, num_inference_steps, guidance_scale, seed):
|
117 |
"""
|
|
|
190 |
torch.cuda.empty_cache()
|
191 |
return None
|
192 |
|
|
|
|
|
|
|
|
|
193 |
def create_thumbnail_grid():
|
194 |
"""Create a gallery of style thumbnails"""
|
195 |
thumbnails = []
|
|
|
214 |
return thumbnails
|
215 |
|
216 |
# Create Gradio interface
|
217 |
+
with gr.Blocks(title="Flux Kontext Style LoRA", theme=gr.themes.Soft()) as demo:
|
218 |
+
gr.Markdown("# 🎨 Flux Styler : Flux Kontext Style LoRA")
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
# Thumbnail Grid Section
|
|
|
|
|
221 |
with gr.Row():
|
222 |
style_gallery = gr.Gallery(
|
223 |
value=create_thumbnail_grid(),
|
|
|
232 |
show_download_button=False
|
233 |
)
|
234 |
|
|
|
|
|
235 |
with gr.Row():
|
236 |
with gr.Column(scale=1):
|
237 |
input_image = gr.Image(
|
238 |
+
label="Input Image",
|
239 |
type="pil",
|
240 |
+
height=400,
|
241 |
+
value=load_default_image()
|
242 |
)
|
243 |
|
244 |
style_dropdown = gr.Dropdown(
|
245 |
choices=list(style_type_lora_dict.keys()),
|
246 |
value="Ghibli",
|
247 |
label="Selected Style",
|
|
|
248 |
elem_id="style_dropdown"
|
249 |
)
|
250 |
|
|
|
257 |
|
258 |
prompt_suffix = gr.Textbox(
|
259 |
label="Additional Instructions (Optional)",
|
260 |
+
placeholder="Add extra details...",
|
261 |
lines=2
|
262 |
)
|
263 |
|
|
|
267 |
maximum=50,
|
268 |
value=24,
|
269 |
step=1,
|
270 |
+
label="Inference Steps"
|
|
|
271 |
)
|
272 |
|
273 |
guidance = gr.Slider(
|
|
|
275 |
maximum=5.0,
|
276 |
value=2.5,
|
277 |
step=0.1,
|
278 |
+
label="Guidance Scale"
|
|
|
279 |
)
|
280 |
|
281 |
seed = gr.Number(
|
282 |
label="Seed",
|
283 |
value=42,
|
284 |
+
precision=0
|
|
|
285 |
)
|
286 |
|
287 |
generate_btn = gr.Button("🎨 Transform Image", variant="primary", size="lg")
|
|
|
292 |
type="pil",
|
293 |
height=400
|
294 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
# Handle gallery selection
|
297 |
def on_gallery_select(evt: gr.SelectData):
|
|
|
319 |
outputs=[style_info]
|
320 |
)
|
321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
# Connect the generate button
|
323 |
generate_btn.click(
|
324 |
fn=style_transfer,
|
|
|
328 |
|
329 |
gr.Markdown("""
|
330 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
Powered by ❤️ https://discord.gg/openfreeai
|
332 |
""")
|
333 |
|