Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
|
| 12 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 13 |
from gradio.themes import Soft
|
| 14 |
from gradio.themes.utils import colors, fonts, sizes
|
|
|
|
| 15 |
|
| 16 |
# --- Custom Theme Definition ---
|
| 17 |
colors.orange_red = colors.Color(
|
|
@@ -22,9 +23,30 @@ colors.orange_red = colors.Color(
|
|
| 22 |
)
|
| 23 |
|
| 24 |
class OrangeRedTheme(Soft):
|
| 25 |
-
def __init__(
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
super().set(
|
|
|
|
| 28 |
button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 29 |
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 30 |
button_primary_text_color="white",
|
|
@@ -93,15 +115,8 @@ def infer(input_image, prompt, lora_adapter, seed=42, randomize_seed=True, guida
|
|
| 93 |
num_images_per_prompt=1,
|
| 94 |
).images[0]
|
| 95 |
|
| 96 |
-
return
|
| 97 |
|
| 98 |
-
@spaces.GPU
|
| 99 |
-
def infer_example(input_image, prompt, lora_adapter):
|
| 100 |
-
"""
|
| 101 |
-
Wrapper function for gr.Examples to call the main infer logic for the slider.
|
| 102 |
-
"""
|
| 103 |
-
(original_image, generated_image), seed, _ = infer(input_image, prompt, lora_adapter, upscale_image=False)
|
| 104 |
-
return (original_image, generated_image), seed
|
| 105 |
|
| 106 |
# --- UI ---
|
| 107 |
css = """
|
|
@@ -119,7 +134,7 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
|
|
| 119 |
|
| 120 |
with gr.Row():
|
| 121 |
with gr.Column():
|
| 122 |
-
input_image = gr.Image(label="Upload Image", type="pil", height=
|
| 123 |
with gr.Row():
|
| 124 |
prompt = gr.Text(
|
| 125 |
label="Edit Prompt",
|
|
@@ -147,8 +162,8 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
|
|
| 147 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 148 |
guidance_scale = gr.Slider(
|
| 149 |
label="Guidance Scale",
|
| 150 |
-
minimum=1,
|
| 151 |
-
maximum=10,
|
| 152 |
step=0.1,
|
| 153 |
value=1.0,
|
| 154 |
)
|
|
@@ -161,7 +176,7 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
|
|
| 161 |
)
|
| 162 |
|
| 163 |
with gr.Column():
|
| 164 |
-
|
| 165 |
reuse_button = gr.Button("Reuse this image", visible=False)
|
| 166 |
|
| 167 |
gr.Examples(
|
|
@@ -172,9 +187,9 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
|
|
| 172 |
["examples/dark.jpg", "Relight the image using soft, diffused lighting that simulates sunlight filtering through curtains.", "Relight"],
|
| 173 |
],
|
| 174 |
inputs=[input_image, prompt, lora_adapter],
|
| 175 |
-
outputs=[
|
| 176 |
fn=infer,
|
| 177 |
-
cache_examples=
|
| 178 |
label="Examples"
|
| 179 |
)
|
| 180 |
|
|
@@ -182,12 +197,12 @@ with gr.Blocks(css=css, theme=orange_red_theme) as demo:
|
|
| 182 |
triggers=[run_button.click, prompt.submit],
|
| 183 |
fn=infer,
|
| 184 |
inputs=[input_image, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
|
| 185 |
-
outputs=[
|
| 186 |
)
|
| 187 |
|
| 188 |
reuse_button.click(
|
| 189 |
-
fn=lambda
|
| 190 |
-
inputs=[
|
| 191 |
outputs=[input_image]
|
| 192 |
)
|
| 193 |
|
|
|
|
| 12 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 13 |
from gradio.themes import Soft
|
| 14 |
from gradio.themes.utils import colors, fonts, sizes
|
| 15 |
+
from typing import Iterable
|
| 16 |
|
| 17 |
# --- Custom Theme Definition ---
|
| 18 |
colors.orange_red = colors.Color(
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
class OrangeRedTheme(Soft):
|
| 26 |
+
def __init__(
|
| 27 |
+
self,
|
| 28 |
+
*,
|
| 29 |
+
primary_hue: colors.Color | str = colors.gray,
|
| 30 |
+
secondary_hue: colors.Color | str = colors.orange_red, # Use the new color
|
| 31 |
+
neutral_hue: colors.Color | str = colors.slate,
|
| 32 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
| 33 |
+
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 34 |
+
fonts.GoogleFont("Outfit"), "Arial", "sans-serif",
|
| 35 |
+
),
|
| 36 |
+
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 37 |
+
fonts.GoogleFont("IBM Plex Mono"), "ui-monospace", "monospace",
|
| 38 |
+
),
|
| 39 |
+
):
|
| 40 |
+
super().__init__(
|
| 41 |
+
primary_hue=primary_hue,
|
| 42 |
+
secondary_hue=secondary_hue,
|
| 43 |
+
neutral_hue=neutral_hue,
|
| 44 |
+
text_size=text_size,
|
| 45 |
+
font=font,
|
| 46 |
+
font_mono=font_mono,
|
| 47 |
+
)
|
| 48 |
super().set(
|
| 49 |
+
background_fill_primary="*primary_50",
|
| 50 |
button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)",
|
| 51 |
button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)",
|
| 52 |
button_primary_text_color="white",
|
|
|
|
| 115 |
num_images_per_prompt=1,
|
| 116 |
).images[0]
|
| 117 |
|
| 118 |
+
return result, seed, gr.Button(visible=True)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# --- UI ---
|
| 122 |
css = """
|
|
|
|
| 134 |
|
| 135 |
with gr.Row():
|
| 136 |
with gr.Column():
|
| 137 |
+
input_image = gr.Image(label="Upload Image", type="pil", height=400)
|
| 138 |
with gr.Row():
|
| 139 |
prompt = gr.Text(
|
| 140 |
label="Edit Prompt",
|
|
|
|
| 162 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 163 |
guidance_scale = gr.Slider(
|
| 164 |
label="Guidance Scale",
|
| 165 |
+
minimum=1.0,
|
| 166 |
+
maximum=10.0,
|
| 167 |
step=0.1,
|
| 168 |
value=1.0,
|
| 169 |
)
|
|
|
|
| 176 |
)
|
| 177 |
|
| 178 |
with gr.Column():
|
| 179 |
+
output_image = gr.Image(label="Output Image", show_label=True, interactive=False, format="png", height=400)
|
| 180 |
reuse_button = gr.Button("Reuse this image", visible=False)
|
| 181 |
|
| 182 |
gr.Examples(
|
|
|
|
| 187 |
["examples/dark.jpg", "Relight the image using soft, diffused lighting that simulates sunlight filtering through curtains.", "Relight"],
|
| 188 |
],
|
| 189 |
inputs=[input_image, prompt, lora_adapter],
|
| 190 |
+
outputs=[output_image, seed],
|
| 191 |
fn=infer,
|
| 192 |
+
cache_examples="lazy",
|
| 193 |
label="Examples"
|
| 194 |
)
|
| 195 |
|
|
|
|
| 197 |
triggers=[run_button.click, prompt.submit],
|
| 198 |
fn=infer,
|
| 199 |
inputs=[input_image, prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
|
| 200 |
+
outputs=[output_image, seed, reuse_button]
|
| 201 |
)
|
| 202 |
|
| 203 |
reuse_button.click(
|
| 204 |
+
fn=lambda image: image,
|
| 205 |
+
inputs=[output_image],
|
| 206 |
outputs=[input_image]
|
| 207 |
)
|
| 208 |
|