linoyts HF Staff commited on
Commit
84489e7
·
verified ·
1 Parent(s): ec6a7bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -172
app.py CHANGED
@@ -32,12 +32,13 @@ def generate_image(prompt, height, width, num_inference_steps, seed, randomize_s
32
  height=int(height),
33
  width=int(width),
34
  num_inference_steps=int(num_inference_steps),
35
- guidance_scale=0.0,
36
  generator=generator,
37
  ).images[0]
38
 
39
  return image, seed
40
 
 
41
  # Example prompts
42
  examples = [
43
  ["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."],
@@ -47,139 +48,82 @@ examples = [
47
  ["Portrait of a wise old wizard with a long white beard, holding a glowing crystal staff, magical forest background"],
48
  ]
49
 
50
- # Custom theme with modern aesthetics (Gradio 6)
51
- custom_theme = gr.themes.Soft(
52
- primary_hue="yellow",
53
- secondary_hue="amber",
54
- neutral_hue="slate",
55
- font=gr.themes.GoogleFont("Inter"),
56
- text_size="lg",
57
- spacing_size="md",
58
- radius_size="lg"
59
- ).set(
60
- button_primary_background_fill="*primary_500",
61
- button_primary_background_fill_hover="*primary_600",
62
- block_title_text_weight="600",
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,69 +140,4 @@ with gr.Blocks(fill_height=True) as demo:
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
- )
 
32
  height=int(height),
33
  width=int(width),
34
  num_inference_steps=int(num_inference_steps),
35
+ guidance_scale=0.0, # Guidance should be 0 for Turbo models
36
  generator=generator,
37
  ).images[0]
38
 
39
  return image, seed
40
 
41
+
42
  # Example prompts
43
  examples = [
44
  ["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."],
 
48
  ["Portrait of a wise old wizard with a long white beard, holding a glowing crystal staff, magical forest background"],
49
  ]
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Build the Gradio interface
52
+ with gr.Blocks(title="Z-Image-Turbo Demo") as demo:
 
53
  gr.Markdown(
54
  """
55
+ # 🎨 Z-Image-Turbo Demo
 
56
 
57
+ Generate high-quality images using the [Tongyi-MAI/Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo) model.
58
+ This turbo model generates images in just 8 inference steps!
59
+ """
 
 
60
  )
61
 
62
+ with gr.Row():
63
+ with gr.Column(scale=1):
 
64
  prompt = gr.Textbox(
65
+ label="Prompt",
66
+ placeholder="Enter your image description...",
67
+ lines=4,
 
 
68
  )
69
 
70
+ with gr.Row():
71
+ height = gr.Slider(
72
+ minimum=512,
73
+ maximum=2048,
74
+ value=1024,
75
+ step=64,
76
+ label="Height",
77
+ )
78
+ width = gr.Slider(
79
+ minimum=512,
80
+ maximum=2048,
81
+ value=1024,
82
+ step=64,
83
+ label="Width",
84
+ )
85
+
86
+ with gr.Row():
 
 
87
  num_inference_steps = gr.Slider(
88
  minimum=1,
89
  maximum=20,
90
  value=9,
91
  step=1,
92
  label="Inference Steps",
93
+ info="9 steps results in 8 DiT forwards",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  )
95
 
96
+ with gr.Row():
97
+ seed = gr.Number(
98
+ label="Seed",
99
+ value=42,
100
+ precision=0,
101
+ )
102
+ randomize_seed = gr.Checkbox(
103
+ label="Randomize Seed",
104
+ value=False,
105
+ )
106
 
107
+ generate_btn = gr.Button("🚀 Generate", variant="primary", size="lg")
 
 
 
 
 
 
108
 
109
+ with gr.Column(scale=1):
 
110
  output_image = gr.Image(
111
  label="Generated Image",
112
  type="pil",
 
 
 
113
  )
 
114
  used_seed = gr.Number(
115
+ label="Seed Used",
116
  interactive=False,
 
117
  )
118
 
119
+ gr.Markdown("### 💡 Example Prompts")
120
+ gr.Examples(
121
+ examples=examples,
122
+ inputs=[prompt],
123
+ cache_examples=False,
 
 
 
 
 
 
124
  )
125
+
126
+ 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")
127
 
128
  # Connect the generate button
129
  generate_btn.click(
 
140
  )
141
 
142
  if __name__ == "__main__":
143
+ demo.launch(mcp_server=True)