akhaliq HF Staff commited on
Commit
2e25444
·
verified ·
1 Parent(s): 4039a38

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +292 -84
  2. requirements.txt +13 -4
app.py CHANGED
@@ -110,144 +110,335 @@ def generate_image(
110
  except Exception as e:
111
  raise gr.Error(f"Generation failed: {str(e)}")
112
 
113
- # Create a custom theme based on Soft theme with Apple-inspired colors
114
- custom_theme = gr.themes.Soft(
115
  primary_hue=gr.themes.colors.blue,
116
  secondary_hue=gr.themes.colors.slate,
117
  neutral_hue=gr.themes.colors.gray,
118
  spacing_size=gr.themes.sizes.spacing_lg,
119
- radius_size=gr.themes.sizes.radius_md,
120
  text_size=gr.themes.sizes.text_lg,
121
- font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
122
- font_mono=[gr.themes.GoogleFont("IBM Plex Mono"), "ui-monospace", "Consolas", "monospace"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  )
124
 
125
- # Custom CSS for additional styling
126
- custom_css = """
 
 
 
127
  .gradio-container {
128
- max-width: 900px !important;
129
  margin: 0 auto !important;
 
 
130
  }
131
 
132
- .main-header {
 
133
  text-align: center;
 
134
  margin-bottom: 2rem;
135
- padding-bottom: 2rem;
136
- border-bottom: 1px solid #e5e5e7;
 
 
 
 
137
  }
138
 
139
- .main-header h1 {
140
- font-size: 3rem !important;
141
- font-weight: 600 !important;
142
- color: #1d1d1f !important;
143
- margin: 0 0 0.5rem 0 !important;
144
- letter-spacing: -1px;
 
 
 
 
145
  }
146
 
147
- .main-header .subtitle {
148
- font-size: 1.25rem !important;
149
- color: #86868b !important;
150
- margin: 0.5rem 0 !important;
 
 
151
  }
152
 
153
  .attribution {
154
- margin-top: 1rem;
155
- font-size: 0.875rem;
156
- color: #86868b;
 
157
  }
158
 
159
  .attribution a {
160
- color: #0071e3 !important;
161
  text-decoration: none;
162
- font-weight: 500;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
 
165
- .footer-info {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  text-align: center;
167
  padding: 2rem 1rem;
168
- color: #86868b;
169
- font-size: 0.875rem;
170
- margin-top: 2rem;
171
- border-top: 1px solid #e5e5e7;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
 
174
- .footer-info p {
175
- margin: 0.25rem 0;
 
 
 
 
176
  }
177
 
178
- button.primary {
179
- background-color: #0071e3 !important;
180
- transition: all 0.2s ease !important;
 
181
  }
182
 
183
- button.primary:hover {
184
- background-color: #0077ed !important;
185
- box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3) !important;
186
  }
187
 
 
188
  @media (max-width: 768px) {
189
- .main-header h1 {
190
- font-size: 2rem !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
192
 
193
- .main-header .subtitle {
194
- font-size: 1rem !important;
 
195
  }
196
  }
 
 
 
 
 
197
  """
198
 
199
  # Create the Gradio interface
200
  with gr.Blocks(
201
- title="Z-Image Turbo",
202
- fill_height=False
203
  ) as demo:
204
 
205
- # Header
206
- with gr.Column(elem_classes="main-header"):
207
- gr.Markdown(
208
- """
209
- # Z-Image Turbo
210
- ### Create stunning images from text
211
- """,
212
- elem_classes="main-header"
213
- )
214
  gr.HTML("""
 
 
215
  <div class="attribution">
216
  Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a>
217
  </div>
218
  """)
219
 
220
- # Prompt input
221
- prompt = gr.Textbox(
222
- placeholder="Describe the image you want to create...",
223
- lines=3,
224
- max_lines=6,
225
- label="Prompt",
226
- show_label=False,
227
- container=True
228
- )
229
-
230
- # Generate button
231
- generate_btn = gr.Button(
232
- "Generate",
233
- variant="primary",
234
- size="lg",
235
- scale=1
236
- )
 
 
237
 
238
- # Output image
239
- output_image = gr.Image(
240
- type="pil",
241
- label="Generated Image",
242
- show_label=False,
243
- buttons=["download"],
244
- container=True
245
- )
 
 
 
246
 
247
  # Footer
248
  gr.HTML("""
249
- <div class="footer-info">
250
- <p>Powered by Z-Image Turbo from Tongyi-MAI</p>
251
  <p>Optimized for fast, high-quality image generation</p>
252
  </div>
253
  """)
@@ -272,6 +463,23 @@ if __name__ == "__main__":
272
  demo.launch(
273
  share=False,
274
  show_error=True,
275
- theme=custom_theme,
276
- css=custom_css
277
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  except Exception as e:
111
  raise gr.Error(f"Generation failed: {str(e)}")
112
 
113
+ # Create a custom Apple-inspired theme
114
+ apple_theme = gr.themes.Soft(
115
  primary_hue=gr.themes.colors.blue,
116
  secondary_hue=gr.themes.colors.slate,
117
  neutral_hue=gr.themes.colors.gray,
118
  spacing_size=gr.themes.sizes.spacing_lg,
119
+ radius_size=gr.themes.sizes.radius_lg,
120
  text_size=gr.themes.sizes.text_lg,
121
+ font=[gr.themes.GoogleFont("SF Pro Display"), gr.themes.GoogleFont("Inter"), "-apple-system", "BlinkMacSystemFont", "system-ui", "sans-serif"],
122
+ font_mono=[gr.themes.GoogleFont("SF Mono"), gr.themes.GoogleFont("IBM Plex Mono"), "ui-monospace", "monospace"],
123
+ ).set(
124
+ body_background_fill='linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)',
125
+ body_background_fill_dark='linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%)',
126
+ button_primary_background_fill='linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
127
+ button_primary_background_fill_hover='linear-gradient(135deg, #764ba2 0%, #667eea 100%)',
128
+ button_primary_text_color='white',
129
+ block_background_fill='rgba(255, 255, 255, 0.95)',
130
+ block_background_fill_dark='rgba(30, 30, 30, 0.95)',
131
+ block_border_width='0px',
132
+ block_shadow='0 20px 60px -15px rgba(0, 0, 0, 0.15)',
133
+ block_shadow_dark='0 20px 60px -15px rgba(0, 0, 0, 0.5)',
134
+ input_background_fill='rgba(255, 255, 255, 0.9)',
135
+ input_background_fill_dark='rgba(40, 40, 40, 0.9)',
136
+ input_border_width='1px',
137
+ input_shadow='0 2px 8px rgba(0, 0, 0, 0.05)',
138
+ input_shadow_focus='0 4px 16px rgba(102, 126, 234, 0.2)',
139
  )
140
 
141
+ # Custom CSS for Apple-style design
142
+ apple_css = """
143
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
144
+
145
+ /* Global Styles */
146
  .gradio-container {
147
+ max-width: 1200px !important;
148
  margin: 0 auto !important;
149
+ padding: 2rem !important;
150
+ font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif !important;
151
  }
152
 
153
+ /* Hero Section */
154
+ .hero-section {
155
  text-align: center;
156
+ padding: 3rem 1rem;
157
  margin-bottom: 2rem;
158
+ background: rgba(255, 255, 255, 0.6);
159
+ backdrop-filter: blur(20px) saturate(180%);
160
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
161
+ border-radius: 24px;
162
+ border: 1px solid rgba(255, 255, 255, 0.3);
163
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
164
  }
165
 
166
+ .hero-title {
167
+ font-size: 3.5rem !important;
168
+ font-weight: 700 !important;
169
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
170
+ -webkit-background-clip: text;
171
+ -webkit-text-fill-color: transparent;
172
+ background-clip: text;
173
+ margin: 0 0 1rem 0 !important;
174
+ letter-spacing: -0.02em;
175
+ line-height: 1.1 !important;
176
  }
177
 
178
+ .hero-subtitle {
179
+ font-size: 1.5rem !important;
180
+ color: #6b7280 !important;
181
+ font-weight: 400 !important;
182
+ margin: 1rem 0 !important;
183
+ letter-spacing: -0.01em;
184
  }
185
 
186
  .attribution {
187
+ margin-top: 1.5rem;
188
+ font-size: 0.95rem;
189
+ color: #9ca3af;
190
+ font-weight: 500;
191
  }
192
 
193
  .attribution a {
194
+ color: #667eea !important;
195
  text-decoration: none;
196
+ font-weight: 600;
197
+ transition: all 0.3s ease;
198
+ }
199
+
200
+ .attribution a:hover {
201
+ color: #764ba2 !important;
202
+ }
203
+
204
+ /* Input Section */
205
+ .input-container {
206
+ background: rgba(255, 255, 255, 0.8);
207
+ backdrop-filter: blur(20px) saturate(180%);
208
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
209
+ border-radius: 20px;
210
+ padding: 2rem;
211
+ margin-bottom: 2rem;
212
+ border: 1px solid rgba(255, 255, 255, 0.3);
213
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
214
+ transition: all 0.3s ease;
215
+ }
216
+
217
+ .input-container:hover {
218
+ box-shadow: 0 12px 48px rgba(0, 0, 0, 0.1);
219
+ transform: translateY(-2px);
220
+ }
221
+
222
+ /* Textbox Styling */
223
+ textarea {
224
+ font-size: 1.1rem !important;
225
+ line-height: 1.6 !important;
226
+ border-radius: 16px !important;
227
+ border: 2px solid #e5e7eb !important;
228
+ padding: 1rem 1.25rem !important;
229
+ transition: all 0.3s ease !important;
230
+ background: rgba(255, 255, 255, 0.95) !important;
231
+ }
232
+
233
+ textarea:focus {
234
+ border-color: #667eea !important;
235
+ box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1) !important;
236
+ outline: none !important;
237
+ }
238
+
239
+ textarea::placeholder {
240
+ color: #9ca3af !important;
241
+ font-weight: 400 !important;
242
+ }
243
+
244
+ /* Button Styling */
245
+ .generate-btn button {
246
+ font-size: 1.125rem !important;
247
+ font-weight: 600 !important;
248
+ padding: 1rem 3rem !important;
249
+ border-radius: 16px !important;
250
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
251
+ border: none !important;
252
+ color: white !important;
253
+ box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3) !important;
254
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
255
+ letter-spacing: 0.02em !important;
256
+ text-transform: none !important;
257
+ min-width: 200px !important;
258
+ }
259
+
260
+ .generate-btn button:hover {
261
+ transform: translateY(-2px) !important;
262
+ box-shadow: 0 12px 32px rgba(102, 126, 234, 0.4) !important;
263
+ background: linear-gradient(135deg, #764ba2 0%, #667eea 100%) !important;
264
+ }
265
+
266
+ .generate-btn button:active {
267
+ transform: translateY(0) !important;
268
+ box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3) !important;
269
  }
270
 
271
+ /* Output Section */
272
+ .output-container {
273
+ background: rgba(255, 255, 255, 0.8);
274
+ backdrop-filter: blur(20px) saturate(180%);
275
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
276
+ border-radius: 20px;
277
+ padding: 2rem;
278
+ border: 1px solid rgba(255, 255, 255, 0.3);
279
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
280
+ overflow: hidden;
281
+ }
282
+
283
+ .output-container img {
284
+ border-radius: 16px !important;
285
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12) !important;
286
+ transition: transform 0.3s ease !important;
287
+ }
288
+
289
+ .output-container img:hover {
290
+ transform: scale(1.02) !important;
291
+ }
292
+
293
+ /* Footer */
294
+ .footer-section {
295
  text-align: center;
296
  padding: 2rem 1rem;
297
+ margin-top: 3rem;
298
+ color: #6b7280;
299
+ font-size: 0.95rem;
300
+ background: rgba(255, 255, 255, 0.4);
301
+ backdrop-filter: blur(10px);
302
+ border-radius: 16px;
303
+ border: 1px solid rgba(255, 255, 255, 0.3);
304
+ }
305
+
306
+ .footer-section p {
307
+ margin: 0.5rem 0;
308
+ font-weight: 500;
309
+ }
310
+
311
+ .footer-highlight {
312
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
313
+ -webkit-background-clip: text;
314
+ -webkit-text-fill-color: transparent;
315
+ background-clip: text;
316
+ font-weight: 600;
317
+ }
318
+
319
+ /* Progress Bar */
320
+ .progress-bar {
321
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
322
+ border-radius: 8px !important;
323
+ }
324
+
325
+ /* Animations */
326
+ @keyframes fadeIn {
327
+ from {
328
+ opacity: 0;
329
+ transform: translateY(20px);
330
+ }
331
+ to {
332
+ opacity: 1;
333
+ transform: translateY(0);
334
+ }
335
+ }
336
+
337
+ .gradio-container > * {
338
+ animation: fadeIn 0.6s ease-out;
339
  }
340
 
341
+ /* Dark mode adjustments */
342
+ .dark .hero-section,
343
+ .dark .input-container,
344
+ .dark .output-container {
345
+ background: rgba(30, 30, 30, 0.8);
346
+ border-color: rgba(255, 255, 255, 0.1);
347
  }
348
 
349
+ .dark textarea {
350
+ background: rgba(40, 40, 40, 0.95) !important;
351
+ border-color: rgba(255, 255, 255, 0.1) !important;
352
+ color: #e5e7eb !important;
353
  }
354
 
355
+ .dark .footer-section {
356
+ background: rgba(30, 30, 30, 0.4);
 
357
  }
358
 
359
+ /* Responsive Design */
360
  @media (max-width: 768px) {
361
+ .hero-title {
362
+ font-size: 2.5rem !important;
363
+ }
364
+
365
+ .hero-subtitle {
366
+ font-size: 1.25rem !important;
367
+ }
368
+
369
+ .gradio-container {
370
+ padding: 1rem !important;
371
+ }
372
+
373
+ .input-container,
374
+ .output-container {
375
+ padding: 1.5rem !important;
376
  }
377
 
378
+ .generate-btn button {
379
+ width: 100% !important;
380
+ padding: 0.875rem 2rem !important;
381
  }
382
  }
383
+
384
+ /* Smooth scrolling */
385
+ html {
386
+ scroll-behavior: smooth;
387
+ }
388
  """
389
 
390
  # Create the Gradio interface
391
  with gr.Blocks(
392
+ title="Z-Image Turbo - AI Image Generation",
393
+ fill_height=False,
394
  ) as demo:
395
 
396
+ # Hero Section
397
+ with gr.Column(elem_classes="hero-section"):
 
 
 
 
 
 
 
398
  gr.HTML("""
399
+ <h1 class="hero-title">Z-Image Turbo</h1>
400
+ <p class="hero-subtitle">Transform your ideas into stunning visuals</p>
401
  <div class="attribution">
402
  Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a>
403
  </div>
404
  """)
405
 
406
+ # Input Section
407
+ with gr.Column(elem_classes="input-container"):
408
+ prompt = gr.Textbox(
409
+ placeholder="Describe your vision in detail... (e.g., 'A serene mountain landscape at sunset with vibrant colors')",
410
+ lines=4,
411
+ max_lines=8,
412
+ label="",
413
+ show_label=False,
414
+ container=False,
415
+ elem_classes="prompt-input"
416
+ )
417
+
418
+ with gr.Row(elem_classes="generate-btn"):
419
+ generate_btn = gr.Button(
420
+ "✨ Generate Image",
421
+ variant="primary",
422
+ size="lg",
423
+ scale=1
424
+ )
425
 
426
+ # Output Section
427
+ with gr.Column(elem_classes="output-container"):
428
+ output_image = gr.Image(
429
+ type="pil",
430
+ label="",
431
+ show_label=False,
432
+ buttons=["download"],
433
+ container=False,
434
+ height=600,
435
+ elem_classes="output-image"
436
+ )
437
 
438
  # Footer
439
  gr.HTML("""
440
+ <div class="footer-section">
441
+ <p>Powered by <span class="footer-highlight">Z-Image Turbo</span> from Tongyi-MAI</p>
442
  <p>Optimized for fast, high-quality image generation</p>
443
  </div>
444
  """)
 
463
  demo.launch(
464
  share=False,
465
  show_error=True,
466
+ theme=apple_theme,
467
+ css=apple_css
468
+ )
469
+
470
+ ---
471
+
472
+ ## Key Apple-Style Design Improvements:
473
+
474
+ 1. **Clean Typography**: Using SF Pro Display-inspired fonts with proper hierarchy
475
+ 2. **Glassmorphism**: Frosted glass effect with backdrop blur for modern Apple aesthetic
476
+ 3. **Smooth Animations**: Fade-in animations and smooth transitions throughout
477
+ 4. **Color Gradients**: Beautiful purple-blue gradients inspired by Apple's marketing
478
+ 5. **Card-based Layout**: Elevated cards with subtle shadows and rounded corners
479
+ 6. **Minimalist UI**: Removed unnecessary labels and clutter
480
+ 7. **Responsive Design**: Mobile-friendly with proper breakpoints
481
+ 8. **Hover Effects**: Smooth interactions on buttons and images
482
+ 9. **Better Spacing**: Generous padding and margins for breathing room
483
+ 10. **Enhanced Button**: Large, prominent CTA button with gradient and shadow effects
484
+
485
+ The design now feels more premium, polished, and aligned with Apple's design philosophy while maintaining full functionality!
requirements.txt CHANGED
@@ -1,5 +1,14 @@
1
- gradio
2
- git+https://github.com/huggingface/diffusers
3
  torch
4
- transformers
5
- accelerate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  torch
2
+ torchvision
3
+ torchaudio
4
+ git+https://github.com/huggingface/diffusers
5
+ git+https://github.com/huggingface/transformers
6
+ sentencepiece
7
+ accelerate
8
+ tokenizers
9
+ spaces
10
+ gradio
11
+ requests
12
+ Pillow
13
+ numpy
14
+ scipy