Spaces:
Running
on
Zero
Running
on
Zero
evalstate
commited on
Commit
·
7c163af
1
Parent(s):
5b0cdfc
update sizes, remove unused checkbox update description, change inference default steps
Browse files
app.py
CHANGED
@@ -19,44 +19,28 @@ pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=dtype).t
|
|
19 |
# --- UI Constants and Helpers ---
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
|
22 |
-
def ensure_divisible_by_16(value):
|
23 |
-
"""Ensures a value is divisible by 16 by rounding to nearest multiple."""
|
24 |
-
return (value + 8) // 16 * 16
|
25 |
-
|
26 |
def get_image_size(aspect_ratio):
|
27 |
"""Converts aspect ratio string to width, height tuple."""
|
28 |
-
|
29 |
-
|
30 |
-
return 1664, 928
|
31 |
-
elif aspect_ratio == "16:9_three_quarter":
|
32 |
-
# 75% of full size, ensuring divisibility by 16
|
33 |
-
width = ensure_divisible_by_16(int(1664 * 0.75))
|
34 |
-
height = ensure_divisible_by_16(int(928 * 0.75))
|
35 |
-
return width, height # 1248, 704
|
36 |
-
elif aspect_ratio == "16:9_half":
|
37 |
-
# 50% of full size
|
38 |
-
return 832, 464
|
39 |
-
# Keep original aspect ratios as fallback
|
40 |
-
elif aspect_ratio == "1:1":
|
41 |
-
return 664, 664
|
42 |
elif aspect_ratio == "16:9":
|
43 |
-
return
|
44 |
elif aspect_ratio == "9:16":
|
45 |
-
return
|
46 |
elif aspect_ratio == "4:3":
|
47 |
-
return
|
48 |
elif aspect_ratio == "3:4":
|
49 |
-
return
|
50 |
elif aspect_ratio == "3:2":
|
51 |
-
return
|
52 |
elif aspect_ratio == "2:3":
|
53 |
-
return
|
54 |
else:
|
55 |
-
# Default to
|
56 |
-
return
|
57 |
|
58 |
# --- Main Inference Function ---
|
59 |
-
@spaces.GPU(duration=
|
60 |
def generate_image(
|
61 |
prompt,
|
62 |
seed=42,
|
@@ -65,7 +49,6 @@ def generate_image(
|
|
65 |
negative_prompt="text, watermark, copyright, blurry, low resolution",
|
66 |
guidance_scale=4.0,
|
67 |
num_inference_steps=30,
|
68 |
-
# prompt_enhance=True,
|
69 |
progress=gr.Progress(track_tqdm=True),
|
70 |
):
|
71 |
"""
|
@@ -86,11 +69,7 @@ def generate_image(
|
|
86 |
|
87 |
# Set up the generator for reproducibility
|
88 |
generator = torch.Generator(device=device).manual_seed(seed)
|
89 |
-
# magic_prompt = "Ultra HD, 4K, cinematic composition"
|
90 |
-
# prompt = prompt + " " + magic_prompt
|
91 |
print(f"Calling pipeline with prompt: '{prompt}'")
|
92 |
-
# if prompt_enhance:
|
93 |
-
# prompt = rewrite(prompt)
|
94 |
print(f"Actual Prompt: '{prompt}'")
|
95 |
print(f"Negative Prompt: '{negative_prompt}'")
|
96 |
print(f"Seed: {seed}, Size: {width}x{height}, Steps: {num_inference_steps}, Guidance: {guidance_scale}")
|
@@ -132,16 +111,14 @@ css = """
|
|
132 |
with gr.Blocks(css=css) as demo:
|
133 |
with gr.Column(elem_id="col-container"):
|
134 |
gr.Markdown('<img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/qwen_image_logo.png" alt="Qwen-Image Logo" width="400" style="display: block; margin: 0 auto;">')
|
135 |
-
gr.Markdown("[Learn more](https://github.com/QwenLM/Qwen-Image) about the Qwen-Image series. Try on [Qwen Chat](https://chat.qwen.ai/), or [download model](https://huggingface.co/Qwen/Qwen-Image) to run locally with ComfyUI or diffusers. <br /> **This version does not
|
136 |
with gr.Row():
|
137 |
prompt = gr.Text(
|
138 |
label="Prompt",
|
139 |
show_label=False,
|
140 |
placeholder="Enter your prompt",
|
141 |
container=False,
|
142 |
-
)
|
143 |
-
|
144 |
-
|
145 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
146 |
|
147 |
result = gr.Image(label="Result", show_label=False, type="pil")
|
@@ -170,7 +147,6 @@ with gr.Blocks(css=css) as demo:
|
|
170 |
choices=["16:9_large", "16:9_three_quarter", "16:9_half"],
|
171 |
value="16:9_half",
|
172 |
)
|
173 |
-
prompt_enhance = gr.Checkbox(label="Prompt Enhance", value=True)
|
174 |
|
175 |
with gr.Row():
|
176 |
guidance_scale = gr.Slider(
|
@@ -186,7 +162,7 @@ with gr.Blocks(css=css) as demo:
|
|
186 |
minimum=1,
|
187 |
maximum=50,
|
188 |
step=1,
|
189 |
-
value=
|
190 |
)
|
191 |
|
192 |
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=generate_image, cache_examples=False)
|
|
|
19 |
# --- UI Constants and Helpers ---
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
|
|
|
|
|
|
|
|
|
22 |
def get_image_size(aspect_ratio):
|
23 |
"""Converts aspect ratio string to width, height tuple."""
|
24 |
+
if aspect_ratio == "1:1":
|
25 |
+
return 1328, 1328
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
elif aspect_ratio == "16:9":
|
27 |
+
return 1664, 928
|
28 |
elif aspect_ratio == "9:16":
|
29 |
+
return 928, 1664
|
30 |
elif aspect_ratio == "4:3":
|
31 |
+
return 1472, 1104
|
32 |
elif aspect_ratio == "3:4":
|
33 |
+
return 1104, 1472
|
34 |
elif aspect_ratio == "3:2":
|
35 |
+
return 1584, 1056
|
36 |
elif aspect_ratio == "2:3":
|
37 |
+
return 1056, 1584
|
38 |
else:
|
39 |
+
# Default to 1:1 if something goes wrong
|
40 |
+
return 1328, 1328
|
41 |
|
42 |
# --- Main Inference Function ---
|
43 |
+
@spaces.GPU(duration=40)
|
44 |
def generate_image(
|
45 |
prompt,
|
46 |
seed=42,
|
|
|
49 |
negative_prompt="text, watermark, copyright, blurry, low resolution",
|
50 |
guidance_scale=4.0,
|
51 |
num_inference_steps=30,
|
|
|
52 |
progress=gr.Progress(track_tqdm=True),
|
53 |
):
|
54 |
"""
|
|
|
69 |
|
70 |
# Set up the generator for reproducibility
|
71 |
generator = torch.Generator(device=device).manual_seed(seed)
|
|
|
|
|
72 |
print(f"Calling pipeline with prompt: '{prompt}'")
|
|
|
|
|
73 |
print(f"Actual Prompt: '{prompt}'")
|
74 |
print(f"Negative Prompt: '{negative_prompt}'")
|
75 |
print(f"Seed: {seed}, Size: {width}x{height}, Steps: {num_inference_steps}, Guidance: {guidance_scale}")
|
|
|
111 |
with gr.Blocks(css=css) as demo:
|
112 |
with gr.Column(elem_id="col-container"):
|
113 |
gr.Markdown('<img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-Image/qwen_image_logo.png" alt="Qwen-Image Logo" width="400" style="display: block; margin: 0 auto;">')
|
114 |
+
gr.Markdown("[Learn more](https://github.com/QwenLM/Qwen-Image) about the Qwen-Image series. Try on [Qwen Chat](https://chat.qwen.ai/), or [download model](https://huggingface.co/Qwen/Qwen-Image) to run locally with ComfyUI or diffusers. <br /> **This version does not include the 'prompt polisher', and uses 20 inference steps by default to target ~30s generation times**.")
|
115 |
with gr.Row():
|
116 |
prompt = gr.Text(
|
117 |
label="Prompt",
|
118 |
show_label=False,
|
119 |
placeholder="Enter your prompt",
|
120 |
container=False,
|
121 |
+
)
|
|
|
|
|
122 |
run_button = gr.Button("Run", scale=0, variant="primary")
|
123 |
|
124 |
result = gr.Image(label="Result", show_label=False, type="pil")
|
|
|
147 |
choices=["16:9_large", "16:9_three_quarter", "16:9_half"],
|
148 |
value="16:9_half",
|
149 |
)
|
|
|
150 |
|
151 |
with gr.Row():
|
152 |
guidance_scale = gr.Slider(
|
|
|
162 |
minimum=1,
|
163 |
maximum=50,
|
164 |
step=1,
|
165 |
+
value=20,
|
166 |
)
|
167 |
|
168 |
gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=generate_image, cache_examples=False)
|