akhaliq HF Staff commited on
Commit
d5bf3b6
·
verified ·
1 Parent(s): be5446b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -83
app.py CHANGED
@@ -166,8 +166,7 @@ t2i_example_prompts = [
166
  ["A cute robot sitting at a desk, digital art style", 1024, 1024, 44],
167
  ]
168
 
169
- # Custom CSS for Apple-style design
170
- # The closing </style> tag is removed as it is not needed when passing as a string to launch()
171
  custom_css = """
172
  @import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&display=swap');
173
 
@@ -178,6 +177,7 @@ custom_css = """
178
  .gradio-container {
179
  max-width: 1400px !important;
180
  margin: auto !important;
 
181
  }
182
 
183
  #component-0 {
@@ -205,10 +205,12 @@ button.selected {
205
  font-weight: 500 !important;
206
  }
207
 
 
208
  .input-image, .output-image {
209
  border-radius: 16px !important;
210
  overflow: hidden !important;
211
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06) !important;
 
212
  }
213
 
214
  textarea, input[type="text"] {
@@ -257,16 +259,30 @@ label {
257
  font-size: 13px !important;
258
  }
259
 
 
260
  .card {
261
  background: white !important;
262
  border-radius: 16px !important;
263
  padding: 24px !important;
264
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04) !important;
265
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  """
267
 
268
  # Build Gradio interface
269
- # In Gradio 6, custom CSS is passed to launch()
270
  with gr.Blocks() as demo:
271
  gr.HTML("""
272
  <div style="text-align: center; padding: 40px 20px 30px 20px;">
@@ -282,41 +298,44 @@ with gr.Blocks() as demo:
282
  with gr.Tabs(selected=0):
283
  # Image Edit Tab (Default)
284
  with gr.TabItem("Edit Image", id=0):
285
- with gr.Row():
286
- with gr.Column(scale=1):
287
- input_image = gr.Image(
288
- label="Upload Image",
289
- type="pil",
290
- sources=["upload", "clipboard"],
291
- height=450,
292
- elem_classes=["input-image"]
293
- )
294
-
295
- prompt = gr.Textbox(
296
- label="What would you like to change?",
297
- placeholder="e.g., Add a mustache, Change to sunset, Make it vintage...",
298
- lines=2,
299
- max_lines=3
300
- )
301
-
302
- seed = gr.Slider(
303
- minimum=0,
304
- maximum=999999,
305
- value=42,
306
- step=1,
307
- label="Seed",
308
- visible=False
309
- )
310
-
311
- edit_btn = gr.Button("Edit Image", variant="primary", size="lg", elem_classes=["primary-btn"])
312
-
313
- with gr.Column(scale=1):
314
- output_image = gr.Image(
315
- label="Result",
316
- type="pil",
317
- height=450,
318
- elem_classes=["output-image"]
319
- )
 
 
 
320
 
321
  gr.HTML("<div style='margin: 30px 0 20px 0;'></div>")
322
 
@@ -332,50 +351,51 @@ with gr.Blocks() as demo:
332
 
333
  # Text-to-Image Tab
334
  with gr.TabItem("Generate Image", id=1):
335
- with gr.Row():
336
- with gr.Column(scale=1):
337
- t2i_prompt = gr.Textbox(
338
- label="Describe your image",
339
- placeholder="e.g., A serene mountain landscape at sunset...",
340
- lines=4,
341
- max_lines=6
342
- )
343
-
344
- with gr.Row():
345
- t2i_width = gr.Slider(
346
- minimum=512,
347
- maximum=2048,
348
- value=1344,
349
- step=64,
350
- label="Width",
351
- )
352
-
353
- t2i_height = gr.Slider(
354
- minimum=512,
355
- maximum=2048,
356
- value=768,
357
- step=64,
358
- label="Height",
359
- )
360
-
361
- t2i_seed = gr.Slider(
362
- minimum=0,
363
- maximum=999999,
364
- value=42,
365
- step=1,
366
- label="Seed",
367
- visible=False
368
- )
369
-
370
- generate_btn = gr.Button("Generate Image", variant="primary", size="lg", elem_classes=["primary-btn"])
371
-
372
- with gr.Column(scale=1):
373
- t2i_output = gr.Image(
374
- label="Result",
375
- type="pil",
376
- height=550,
377
- elem_classes=["output-image"]
378
- )
 
379
 
380
  gr.HTML("<div style='margin: 30px 0 20px 0;'></div>")
381
 
@@ -416,6 +436,5 @@ with gr.Blocks() as demo:
416
  if __name__ == "__main__":
417
  demo.launch(
418
  mcp_server=True,
419
- # *** Gradio 6 Migration: CSS is now passed to launch() ***
420
  css=custom_css
421
  )
 
166
  ["A cute robot sitting at a desk, digital art style", 1024, 1024, 44],
167
  ]
168
 
169
+ # Custom CSS for Apple-style design and responsiveness
 
170
  custom_css = """
171
  @import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&display=swap');
172
 
 
177
  .gradio-container {
178
  max-width: 1400px !important;
179
  margin: auto !important;
180
+ padding: 0 16px; /* Added padding for mobile/small desktop */
181
  }
182
 
183
  #component-0 {
 
205
  font-weight: 500 !important;
206
  }
207
 
208
+ /* Ensure images scale correctly on mobile */
209
  .input-image, .output-image {
210
  border-radius: 16px !important;
211
  overflow: hidden !important;
212
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06) !important;
213
+ min-height: 250px; /* Base minimum height for better mobile scaling */
214
  }
215
 
216
  textarea, input[type="text"] {
 
259
  font-size: 13px !important;
260
  }
261
 
262
+ /* The .card class targets the underlying gr-panel component for the elevated look */
263
  .card {
264
  background: white !important;
265
  border-radius: 16px !important;
266
  padding: 24px !important;
267
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04) !important;
268
  }
269
+
270
+ /* Mobile Responsiveness: Adjust padding/margins for smaller screens */
271
+ @media (max-width: 768px) {
272
+ .gradio-container {
273
+ padding: 0 8px !important;
274
+ }
275
+ .card {
276
+ padding: 16px !important;
277
+ }
278
+ .primary-btn {
279
+ padding: 12px 24px !important;
280
+ font-size: 15px !important;
281
+ }
282
+ }
283
  """
284
 
285
  # Build Gradio interface
 
286
  with gr.Blocks() as demo:
287
  gr.HTML("""
288
  <div style="text-align: center; padding: 40px 20px 30px 20px;">
 
298
  with gr.Tabs(selected=0):
299
  # Image Edit Tab (Default)
300
  with gr.TabItem("Edit Image", id=0):
301
+ # Use gr.Column with variant="panel" to get the 'card' look for inputs
302
+ with gr.Column(variant="panel", scale=1):
303
+ gr.Markdown("### 🖼️ Input Image & Controls")
304
+ input_image = gr.Image(
305
+ label="Upload Image",
306
+ type="pil",
307
+ sources=["upload", "clipboard"],
308
+ height=450,
309
+ elem_classes=["input-image"]
310
+ )
311
+
312
+ prompt = gr.Textbox(
313
+ label="What would you like to change?",
314
+ placeholder="e.g., Add a mustache, Change to sunset, Make it vintage...",
315
+ lines=2,
316
+ max_lines=3
317
+ )
318
+
319
+ seed = gr.Slider(
320
+ minimum=0,
321
+ maximum=999999,
322
+ value=42,
323
+ step=1,
324
+ label="Seed",
325
+ visible=False
326
+ )
327
+
328
+ edit_btn = gr.Button("Edit Image", variant="primary", size="lg", elem_classes=["primary-btn"])
329
+
330
+ # Use gr.Column with variant="panel" for the output image
331
+ with gr.Column(variant="panel", scale=1):
332
+ gr.Markdown("### ✨ Result")
333
+ output_image = gr.Image(
334
+ label="Result",
335
+ type="pil",
336
+ height=450,
337
+ elem_classes=["output-image"]
338
+ )
339
 
340
  gr.HTML("<div style='margin: 30px 0 20px 0;'></div>")
341
 
 
351
 
352
  # Text-to-Image Tab
353
  with gr.TabItem("Generate Image", id=1):
354
+ with gr.Column(variant="panel", scale=1):
355
+ gr.Markdown("### 🎨 Generation Controls")
356
+ t2i_prompt = gr.Textbox(
357
+ label="Describe your image",
358
+ placeholder="e.g., A serene mountain landscape at sunset...",
359
+ lines=4,
360
+ max_lines=6
361
+ )
362
+
363
+ # Sliders remain vertical
364
+ t2i_width = gr.Slider(
365
+ minimum=512,
366
+ maximum=2048,
367
+ value=1344,
368
+ step=64,
369
+ label="Width",
370
+ )
371
+
372
+ t2i_height = gr.Slider(
373
+ minimum=512,
374
+ maximum=2048,
375
+ value=768,
376
+ step=64,
377
+ label="Height",
378
+ )
379
+
380
+ t2i_seed = gr.Slider(
381
+ minimum=0,
382
+ maximum=999999,
383
+ value=42,
384
+ step=1,
385
+ label="Seed",
386
+ visible=False
387
+ )
388
+
389
+ generate_btn = gr.Button("Generate Image", variant="primary", size="lg", elem_classes=["primary-btn"])
390
+
391
+ with gr.Column(variant="panel", scale=1):
392
+ gr.Markdown("### ✨ Result")
393
+ t2i_output = gr.Image(
394
+ label="Result",
395
+ type="pil",
396
+ height=550,
397
+ elem_classes=["output-image"]
398
+ )
399
 
400
  gr.HTML("<div style='margin: 30px 0 20px 0;'></div>")
401
 
 
436
  if __name__ == "__main__":
437
  demo.launch(
438
  mcp_server=True,
 
439
  css=custom_css
440
  )