akhaliq HF Staff commited on
Commit
a6f47af
·
verified ·
1 Parent(s): 195c536

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +156 -227
  2. requirements.txt +1 -1
app.py CHANGED
@@ -110,336 +110,270 @@ def generate_image(
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
  """)
445
 
@@ -448,21 +382,16 @@ with gr.Blocks(
448
  fn=generate_image,
449
  inputs=prompt,
450
  outputs=output_image,
451
- api_name="generate"
452
  )
453
 
454
- # Also allow generation on Enter key
455
  prompt.submit(
456
  fn=generate_image,
457
  inputs=prompt,
458
- outputs=output_image
459
  )
460
 
461
- # Launch the app
462
  if __name__ == "__main__":
463
  demo.launch(
464
  share=False,
465
  show_error=True,
466
- theme=apple_theme,
467
- css=apple_css
468
  )
 
110
  except Exception as e:
111
  raise gr.Error(f"Generation failed: {str(e)}")
112
 
113
+ # Create 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_md,
121
+ font=[gr.themes.GoogleFont("Inter"), "SF Pro Display", "-apple-system", "BlinkMacSystemFont", "system-ui", "sans-serif"],
122
+ font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "SF Mono", "ui-monospace", "monospace"],
123
  ).set(
124
+ body_background_fill='#f5f5f7',
125
+ body_background_fill_dark='#000000',
126
+ button_primary_background_fill='#0071e3',
127
+ button_primary_background_fill_hover='#0077ed',
128
+ button_primary_text_color='#ffffff',
129
+ block_background_fill='#ffffff',
130
+ block_background_fill_dark='#1d1d1f',
131
  block_border_width='0px',
132
+ block_shadow='0 2px 12px rgba(0, 0, 0, 0.08)',
133
+ block_shadow_dark='0 2px 12px rgba(0, 0, 0, 0.4)',
134
+ input_background_fill='#ffffff',
135
+ input_background_fill_dark='#1d1d1f',
136
  input_border_width='1px',
137
+ input_border_color='#d2d2d7',
138
+ input_border_color_dark='#424245',
139
+ input_shadow='none',
140
+ input_shadow_focus='0 0 0 4px rgba(0, 113, 227, 0.15)',
141
  )
142
 
143
+ # Apple-style CSS
144
  apple_css = """
 
 
145
  /* Global Styles */
146
  .gradio-container {
147
+ max-width: 980px !important;
148
  margin: 0 auto !important;
149
+ padding: 48px 20px !important;
150
+ font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'Roboto', sans-serif !important;
151
  }
152
 
153
+ /* Header */
154
+ .header-container {
155
  text-align: center;
156
+ margin-bottom: 48px;
 
 
 
 
 
 
 
157
  }
158
 
159
+ .main-title {
160
+ font-size: 56px !important;
161
+ font-weight: 600 !important;
162
+ letter-spacing: -0.02em !important;
163
+ line-height: 1.07 !important;
164
+ color: #1d1d1f !important;
165
+ margin: 0 0 12px 0 !important;
 
 
 
166
  }
167
 
168
+ .subtitle {
169
+ font-size: 21px !important;
 
170
  font-weight: 400 !important;
171
+ line-height: 1.38 !important;
172
+ color: #6e6e73 !important;
173
+ margin: 0 0 24px 0 !important;
 
 
 
 
 
 
174
  }
175
 
176
+ .attribution-link {
177
+ display: inline-block;
178
+ font-size: 14px !important;
179
+ color: #0071e3 !important;
180
+ text-decoration: none !important;
181
+ font-weight: 400 !important;
182
+ transition: color 0.2s ease !important;
183
  }
184
 
185
+ .attribution-link:hover {
186
+ color: #0077ed !important;
187
+ text-decoration: underline !important;
188
  }
189
 
190
  /* Input Section */
191
+ .input-section {
192
+ background: #ffffff;
193
+ border-radius: 18px;
194
+ padding: 32px;
195
+ margin-bottom: 24px;
196
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
 
 
 
 
 
 
 
 
 
197
  }
198
 
199
+ /* Textbox */
200
  textarea {
201
+ font-size: 17px !important;
202
+ line-height: 1.47 !important;
203
+ border-radius: 12px !important;
204
+ border: 1px solid #d2d2d7 !important;
205
+ padding: 12px 16px !important;
206
+ transition: all 0.2s ease !important;
207
+ background: #ffffff !important;
208
+ font-family: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif !important;
209
  }
210
 
211
  textarea:focus {
212
+ border-color: #0071e3 !important;
213
+ box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15) !important;
214
  outline: none !important;
215
  }
216
 
217
  textarea::placeholder {
218
+ color: #86868b !important;
 
219
  }
220
 
221
+ /* Button */
222
+ button.primary {
223
+ font-size: 17px !important;
224
+ font-weight: 400 !important;
225
+ padding: 12px 32px !important;
226
+ border-radius: 980px !important;
227
+ background: #0071e3 !important;
228
  border: none !important;
229
+ color: #ffffff !important;
230
+ min-height: 44px !important;
231
+ transition: all 0.2s ease !important;
232
+ letter-spacing: -0.01em !important;
233
+ cursor: pointer !important;
 
234
  }
235
 
236
+ button.primary:hover {
237
+ background: #0077ed !important;
238
+ transform: scale(1.02) !important;
 
239
  }
240
 
241
+ button.primary:active {
242
+ transform: scale(0.98) !important;
 
243
  }
244
 
245
  /* Output Section */
246
+ .output-section {
247
+ background: #ffffff;
248
+ border-radius: 18px;
249
+ padding: 32px;
250
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
 
 
 
251
  overflow: hidden;
252
  }
253
 
254
+ .output-section img {
255
+ border-radius: 12px !important;
256
+ width: 100% !important;
257
+ height: auto !important;
 
 
 
 
258
  }
259
 
260
  /* Footer */
261
+ .footer-text {
262
  text-align: center;
263
+ margin-top: 48px;
264
+ font-size: 14px !important;
265
+ color: #86868b !important;
266
+ line-height: 1.43 !important;
 
 
 
 
267
  }
268
 
269
+ /* Progress */
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  .progress-bar {
271
+ background: #0071e3 !important;
272
+ border-radius: 4px !important;
273
  }
274
 
275
+ /* Dark Mode */
276
+ .dark .main-title {
277
+ color: #f5f5f7 !important;
 
 
 
 
 
 
 
278
  }
279
 
280
+ .dark .subtitle {
281
+ color: #a1a1a6 !important;
282
  }
283
 
284
+ .dark .input-section,
285
+ .dark .output-section {
286
+ background: #1d1d1f;
287
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
 
 
288
  }
289
 
290
  .dark textarea {
291
+ background: #1d1d1f !important;
292
+ border-color: #424245 !important;
293
+ color: #f5f5f7 !important;
294
  }
295
 
296
+ .dark textarea::placeholder {
297
+ color: #86868b !important;
298
  }
299
 
300
+ /* Responsive */
301
+ @media (max-width: 734px) {
302
+ .main-title {
303
+ font-size: 40px !important;
304
  }
305
 
306
+ .subtitle {
307
+ font-size: 19px !important;
308
  }
309
 
310
  .gradio-container {
311
+ padding: 32px 16px !important;
312
  }
313
 
314
+ .input-section,
315
+ .output-section {
316
+ padding: 24px !important;
 
 
 
 
 
317
  }
318
  }
319
 
320
+ /* Remove default Gradio styling */
321
+ .contain {
322
+ padding: 0 !important;
323
  }
324
  """
325
 
326
+ # Create the interface
327
  with gr.Blocks(
328
+ title="Z-Image Turbo",
329
+ theme=apple_theme,
330
+ css=apple_css,
331
  fill_height=False,
332
  ) as demo:
333
 
334
+ # Header
335
+ gr.HTML("""
336
+ <div class="header-container">
337
+ <h1 class="main-title">Z-Image Turbo</h1>
338
+ <p class="subtitle">Transform your ideas into stunning visuals with AI</p>
339
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="attribution-link">
340
+ Built with anycoder
341
+ </a>
342
+ </div>
343
+ """)
344
 
345
  # Input Section
346
+ with gr.Column(elem_classes="input-section"):
347
  prompt = gr.Textbox(
348
+ placeholder="Describe the image you want to create...",
349
+ lines=3,
350
+ max_lines=6,
351
  label="",
352
  show_label=False,
353
  container=False,
 
354
  )
355
 
356
+ generate_btn = gr.Button(
357
+ "Generate",
358
+ variant="primary",
359
+ size="lg",
360
+ elem_classes="primary"
361
+ )
 
362
 
363
  # Output Section
364
+ with gr.Column(elem_classes="output-section"):
365
  output_image = gr.Image(
366
  type="pil",
367
  label="",
368
  show_label=False,
 
369
  container=False,
370
+ show_download_button=True,
 
371
  )
372
 
373
  # Footer
374
  gr.HTML("""
375
+ <div class="footer-text">
376
+ <p>Powered by Z-Image Turbo from Tongyi-MAI</p>
 
377
  </div>
378
  """)
379
 
 
382
  fn=generate_image,
383
  inputs=prompt,
384
  outputs=output_image,
 
385
  )
386
 
 
387
  prompt.submit(
388
  fn=generate_image,
389
  inputs=prompt,
390
+ outputs=output_image,
391
  )
392
 
 
393
  if __name__ == "__main__":
394
  demo.launch(
395
  share=False,
396
  show_error=True,
 
 
397
  )
requirements.txt CHANGED
@@ -11,4 +11,4 @@ gradio
11
  requests
12
  Pillow
13
  numpy
14
- scipy
 
11
  requests
12
  Pillow
13
  numpy
14
+ scipy