Spaces:
Running
on
Zero
Running
on
Zero
π¨ Redesign from AnyCoder
#5
by
mrfakename
- opened
app.py
CHANGED
|
@@ -30,13 +30,12 @@ def generate_image(prompt, height, width, num_inference_steps, seed, randomize_s
|
|
| 30 |
height=int(height),
|
| 31 |
width=int(width),
|
| 32 |
num_inference_steps=int(num_inference_steps),
|
| 33 |
-
guidance_scale=0.0,
|
| 34 |
generator=generator,
|
| 35 |
).images[0]
|
| 36 |
|
| 37 |
return image, seed
|
| 38 |
|
| 39 |
-
|
| 40 |
# Example prompts
|
| 41 |
examples = [
|
| 42 |
["Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp, bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda, blurred colorful distant lights."],
|
|
@@ -46,82 +45,141 @@ examples = [
|
|
| 46 |
["Portrait of a wise old wizard with a long white beard, holding a glowing crystal staff, magical forest background"],
|
| 47 |
]
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
# Build the Gradio interface
|
| 50 |
-
with gr.Blocks(
|
|
|
|
| 51 |
gr.Markdown(
|
| 52 |
"""
|
| 53 |
-
# π¨ Z-Image-Turbo
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
-
with gr.Row():
|
| 61 |
-
|
|
|
|
| 62 |
prompt = gr.Textbox(
|
| 63 |
-
label="Prompt",
|
| 64 |
-
placeholder="
|
| 65 |
-
lines=
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
-
with gr.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
num_inference_steps = gr.Slider(
|
| 86 |
minimum=1,
|
| 87 |
maximum=20,
|
| 88 |
value=9,
|
| 89 |
step=1,
|
| 90 |
label="Inference Steps",
|
| 91 |
-
info="9 steps
|
| 92 |
)
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
)
|
| 104 |
|
| 105 |
-
generate_btn = gr.Button(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
|
|
|
| 108 |
output_image = gr.Image(
|
| 109 |
label="Generated Image",
|
| 110 |
type="pil",
|
|
|
|
|
|
|
|
|
|
| 111 |
)
|
|
|
|
| 112 |
used_seed = gr.Number(
|
| 113 |
-
label="Seed Used",
|
| 114 |
interactive=False,
|
|
|
|
| 115 |
)
|
| 116 |
|
| 117 |
-
|
| 118 |
-
gr.
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
)
|
| 123 |
-
|
| 124 |
-
gr.Markdown("Demo by [mrfakename](https://x.com/realmrfakename). Model by Alibaba. The model is licensed under Apache 2.0, you can use generated images commercially! Thanks to [multimodalart](https://huggingface.co/multimodalart) for the FA3 + AoTI enhancements/speedups")
|
| 125 |
|
| 126 |
# Connect the generate button
|
| 127 |
generate_btn.click(
|
|
@@ -138,4 +196,70 @@ with gr.Blocks(title="Z-Image-Turbo Demo") as demo:
|
|
| 138 |
)
|
| 139 |
|
| 140 |
if __name__ == "__main__":
|
| 141 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
height=int(height),
|
| 31 |
width=int(width),
|
| 32 |
num_inference_steps=int(num_inference_steps),
|
| 33 |
+
guidance_scale=0.0,
|
| 34 |
generator=generator,
|
| 35 |
).images[0]
|
| 36 |
|
| 37 |
return image, seed
|
| 38 |
|
|
|
|
| 39 |
# Example prompts
|
| 40 |
examples = [
|
| 41 |
["Young Chinese woman in red Hanfu, intricate embroidery. Impeccable makeup, red floral forehead pattern. Elaborate high bun, golden phoenix headdress, red flowers, beads. Holds round folding fan with lady, trees, bird. Neon lightning-bolt lamp, bright yellow glow, above extended left palm. Soft-lit outdoor night background, silhouetted tiered pagoda, blurred colorful distant lights."],
|
|
|
|
| 45 |
["Portrait of a wise old wizard with a long white beard, holding a glowing crystal staff, magical forest background"],
|
| 46 |
]
|
| 47 |
|
| 48 |
+
# Custom theme with modern aesthetics
|
| 49 |
+
custom_theme = gr.themes.Soft(
|
| 50 |
+
primary_hue="yellow",
|
| 51 |
+
secondary_hue="amber",
|
| 52 |
+
neutral_hue="slate",
|
| 53 |
+
font=gr.themes.GoogleFont("Inter"),
|
| 54 |
+
text_size="lg",
|
| 55 |
+
spacing_size="md",
|
| 56 |
+
radius_size="lg"
|
| 57 |
+
).set(
|
| 58 |
+
button_primary_background_fill="*primary_500",
|
| 59 |
+
button_primary_background_fill_hover="*primary_600",
|
| 60 |
+
button_primary_text_weight="600",
|
| 61 |
+
block_title_text_weight="600",
|
| 62 |
+
block_label_text_weight="500",
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
# Build the Gradio interface
|
| 66 |
+
with gr.Blocks(fill_height=True) as demo:
|
| 67 |
+
# Header
|
| 68 |
gr.Markdown(
|
| 69 |
"""
|
| 70 |
+
# π¨ Z-Image-Turbo
|
| 71 |
+
**Ultra-fast AI image generation** β’ Generate stunning images in just 8 steps
|
| 72 |
|
| 73 |
+
<div style="margin-top: 0.5rem; opacity: 0.8;">
|
| 74 |
+
Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: inherit; text-decoration: underline;">anycoder</a>
|
| 75 |
+
</div>
|
| 76 |
+
""",
|
| 77 |
+
elem_classes="header-text"
|
| 78 |
)
|
| 79 |
|
| 80 |
+
with gr.Row(equal_height=False):
|
| 81 |
+
# Left column - Input controls
|
| 82 |
+
with gr.Column(scale=1, min_width=320):
|
| 83 |
prompt = gr.Textbox(
|
| 84 |
+
label="β¨ Your Prompt",
|
| 85 |
+
placeholder="Describe the image you want to create...",
|
| 86 |
+
lines=5,
|
| 87 |
+
max_lines=10,
|
| 88 |
+
autofocus=True,
|
| 89 |
)
|
| 90 |
|
| 91 |
+
with gr.Accordion("βοΈ Advanced Settings", open=False):
|
| 92 |
+
with gr.Row():
|
| 93 |
+
height = gr.Slider(
|
| 94 |
+
minimum=512,
|
| 95 |
+
maximum=2048,
|
| 96 |
+
value=1024,
|
| 97 |
+
step=64,
|
| 98 |
+
label="Height",
|
| 99 |
+
info="Image height in pixels"
|
| 100 |
+
)
|
| 101 |
+
width = gr.Slider(
|
| 102 |
+
minimum=512,
|
| 103 |
+
maximum=2048,
|
| 104 |
+
value=1024,
|
| 105 |
+
step=64,
|
| 106 |
+
label="Width",
|
| 107 |
+
info="Image width in pixels"
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
num_inference_steps = gr.Slider(
|
| 111 |
minimum=1,
|
| 112 |
maximum=20,
|
| 113 |
value=9,
|
| 114 |
step=1,
|
| 115 |
label="Inference Steps",
|
| 116 |
+
info="9 steps = 8 DiT forwards (recommended)"
|
| 117 |
)
|
| 118 |
+
|
| 119 |
+
with gr.Row():
|
| 120 |
+
randomize_seed = gr.Checkbox(
|
| 121 |
+
label="π² Random Seed",
|
| 122 |
+
value=True,
|
| 123 |
+
)
|
| 124 |
+
seed = gr.Number(
|
| 125 |
+
label="Seed",
|
| 126 |
+
value=42,
|
| 127 |
+
precision=0,
|
| 128 |
+
visible=False,
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
def toggle_seed(randomize):
|
| 132 |
+
return gr.Number(visible=not randomize)
|
| 133 |
+
|
| 134 |
+
randomize_seed.change(
|
| 135 |
+
toggle_seed,
|
| 136 |
+
inputs=[randomize_seed],
|
| 137 |
+
outputs=[seed]
|
| 138 |
)
|
| 139 |
|
| 140 |
+
generate_btn = gr.Button(
|
| 141 |
+
"π Generate Image",
|
| 142 |
+
variant="primary",
|
| 143 |
+
size="lg",
|
| 144 |
+
scale=1
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
# Example prompts
|
| 148 |
+
gr.Examples(
|
| 149 |
+
examples=examples,
|
| 150 |
+
inputs=[prompt],
|
| 151 |
+
label="π‘ Try these prompts",
|
| 152 |
+
examples_per_page=5,
|
| 153 |
+
)
|
| 154 |
|
| 155 |
+
# Right column - Output
|
| 156 |
+
with gr.Column(scale=1, min_width=320):
|
| 157 |
output_image = gr.Image(
|
| 158 |
label="Generated Image",
|
| 159 |
type="pil",
|
| 160 |
+
show_label=False,
|
| 161 |
+
height=600,
|
| 162 |
+
buttons=["download", "share"],
|
| 163 |
)
|
| 164 |
+
|
| 165 |
used_seed = gr.Number(
|
| 166 |
+
label="π² Seed Used",
|
| 167 |
interactive=False,
|
| 168 |
+
container=True,
|
| 169 |
)
|
| 170 |
|
| 171 |
+
# Footer credits
|
| 172 |
+
gr.Markdown(
|
| 173 |
+
"""
|
| 174 |
+
---
|
| 175 |
+
<div style="text-align: center; opacity: 0.7; font-size: 0.9em; margin-top: 1rem;">
|
| 176 |
+
<strong>Model:</strong> <a href="https://huggingface.co/Tongyi-MAI/Z-Image-Turbo" target="_blank">Tongyi-MAI/Z-Image-Turbo</a> (Apache 2.0 License) β’
|
| 177 |
+
<strong>Demo by:</strong> <a href="https://x.com/realmrfakename" target="_blank">@mrfakename</a> β’
|
| 178 |
+
<strong>Optimizations:</strong> <a href="https://huggingface.co/multimodalart" target="_blank">@multimodalart</a> (FA3 + AoTI)
|
| 179 |
+
</div>
|
| 180 |
+
""",
|
| 181 |
+
elem_classes="footer-text"
|
| 182 |
)
|
|
|
|
|
|
|
| 183 |
|
| 184 |
# Connect the generate button
|
| 185 |
generate_btn.click(
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
+
demo.launch(
|
| 200 |
+
theme=custom_theme,
|
| 201 |
+
css="""
|
| 202 |
+
.header-text h1 {
|
| 203 |
+
font-size: 2.5rem !important;
|
| 204 |
+
font-weight: 700 !important;
|
| 205 |
+
margin-bottom: 0.5rem !important;
|
| 206 |
+
background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
|
| 207 |
+
-webkit-background-clip: text;
|
| 208 |
+
-webkit-text-fill-color: transparent;
|
| 209 |
+
background-clip: text;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
.header-text p {
|
| 213 |
+
font-size: 1.1rem !important;
|
| 214 |
+
color: #64748b !important;
|
| 215 |
+
margin-top: 0 !important;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.footer-text {
|
| 219 |
+
padding: 1rem 0;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
.footer-text a {
|
| 223 |
+
color: #f59e0b !important;
|
| 224 |
+
text-decoration: none !important;
|
| 225 |
+
font-weight: 500;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.footer-text a:hover {
|
| 229 |
+
text-decoration: underline !important;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/* Mobile optimizations */
|
| 233 |
+
@media (max-width: 768px) {
|
| 234 |
+
.header-text h1 {
|
| 235 |
+
font-size: 1.8rem !important;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
.header-text p {
|
| 239 |
+
font-size: 1rem !important;
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
/* Smooth transitions */
|
| 244 |
+
button, .gr-button {
|
| 245 |
+
transition: all 0.2s ease !important;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
button:hover, .gr-button:hover {
|
| 249 |
+
transform: translateY(-1px);
|
| 250 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
/* Better spacing */
|
| 254 |
+
.gradio-container {
|
| 255 |
+
max-width: 1400px !important;
|
| 256 |
+
margin: 0 auto !important;
|
| 257 |
+
}
|
| 258 |
+
""",
|
| 259 |
+
footer_links=[
|
| 260 |
+
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"},
|
| 261 |
+
"api",
|
| 262 |
+
"gradio"
|
| 263 |
+
],
|
| 264 |
+
mcp_server=True
|
| 265 |
+
)
|