Madiy commited on
Commit
be943c2
·
verified ·
1 Parent(s): 143c167

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -42
app.py CHANGED
@@ -384,76 +384,97 @@ def outpaint_image(image, direction, extend_percent, custom_prompt, progress=gr.
384
  # GRADIO UI
385
  # ================================================================
386
 
387
- with gr.Blocks(title="CanvasAI") as demo:
388
-
389
- gr.Markdown("# CanvasAI")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  gr.Markdown(
391
  "**Enhance** with Real-ESRGAN | "
392
  "**Colorize** B&W photos with DDColor | "
393
  "**Outpaint** to extend any scene with SD2"
394
  )
 
395
 
396
  with gr.Tabs():
397
-
398
- with gr.Tab("Enhance"):
399
- gr.Markdown("Upscale and sharpen any image 2x or 4x using Real-ESRGAN.")
400
- with gr.Row():
401
- with gr.Column():
402
- enh_input = gr.Image(label="Upload Image", type="pil")
403
- enh_scale = gr.Dropdown(
404
- choices=["2x", "4x"], value="4x", label="Upscale Factor",
405
- info="4x recommended. Use 2x for very large inputs."
 
 
406
  )
407
- enh_btn = gr.Button("Enhance", variant="primary")
408
- with gr.Column():
409
- enh_output = gr.Image(label="Result", type="pil", interactive=False)
410
- enh_info = gr.Textbox(label="Size Info", interactive=False)
411
 
412
  enh_btn.click(fn=enhance_image, inputs=[enh_input, enh_scale], outputs=[enh_output, enh_info])
413
-
414
  with gr.Tab("Colorize"):
415
- gr.Markdown(
416
- "Upload a black and white image. "
417
- "DDColor adds natural, realistic colors while preserving the original structure."
418
  )
419
- with gr.Row():
420
- with gr.Column():
421
- col_input = gr.Image(label="Upload B&W Image", type="pil")
422
  col_strength = gr.Slider(
423
  minimum=0.5, maximum=1.0, value=0.9, step=0.05,
424
  label="Color Strength",
425
  # BUG 10 FIX: maximum changed from 0.7 to 1.0
426
- # User can now reach full DDColor output at 1.0
427
- info="0.5 = subtle tint. 1.0 = full vivid DDColor output."
428
  )
429
- col_btn = gr.Button("Colorize", variant="primary")
430
  with gr.Column():
431
- col_output = gr.Image(label="Colorized Result", type="pil", interactive=False)
 
432
 
433
  col_btn.click(fn=colour_image, inputs=[col_input, col_strength], outputs=[col_output])
434
-
435
  with gr.Tab("Outpaint"):
436
- gr.Markdown(
437
- "Upload an image and extend it in any direction. "
438
- "BLIP reads the scene automatically — no prompt needed."
439
  )
440
- with gr.Row():
441
- with gr.Column():
442
- out_input = gr.Image(label="Upload Image", type="pil")
443
  out_dir = gr.Radio(
444
  choices=["Horizontal", "Vertical", "Both"], value="Horizontal",
445
  label="Extension Direction",
446
  info="Horizontal = left & right | Vertical = top & bottom | Both = all sides"
447
  )
448
  out_pct = gr.Slider(minimum=10, maximum=50, value=25, step=5, label="Extend by (%)")
449
- out_prompt = gr.Textbox(
450
- label="Custom Prompt (optional)",
451
- placeholder="Leave empty BLIP reads your image automatically",
452
- lines=2
453
- )
454
- out_btn = gr.Button("Outpaint", variant="primary")
455
- with gr.Column():
456
- out_output = gr.Image(label="Result", type="pil", interactive=False)
 
 
 
 
457
  out_caption = gr.Textbox(label="Prompt Used", interactive=False, lines=4)
458
 
459
  out_btn.click(
@@ -461,5 +482,13 @@ with gr.Blocks(title="CanvasAI") as demo:
461
  inputs=[out_input, out_dir, out_pct, out_prompt],
462
  outputs=[out_output, out_caption]
463
  )
 
 
 
 
 
 
 
 
464
 
465
  demo.launch()
 
384
  # GRADIO UI
385
  # ================================================================
386
 
387
+ with gr.Blocks(
388
+ title="CanvasAI",
389
+ theme= gr.themes.Soft(
390
+ primary_hue= "violet",
391
+ secondary_hue="blue",
392
+ neutral_hue="slate",
393
+ font= gr.themes.GoogleFont("Inter"),
394
+ font_mono= gr.themes.GoogleFont("JetBrains Mono")
395
+ ),
396
+ js="""
397
+ function() {
398
+ document.body.classList.add('dark');
399
+ }
400
+ """) as demo:
401
+
402
+ gr.Markdown("""# CanvasAI
403
+ ### AI-powered image enhancement, colorization, and outpainting""")
404
  gr.Markdown(
405
  "**Enhance** with Real-ESRGAN | "
406
  "**Colorize** B&W photos with DDColor | "
407
  "**Outpaint** to extend any scene with SD2"
408
  )
409
+ gr.Markdown("---")
410
 
411
  with gr.Tabs():
412
+ #---------Enhance----------------
413
+ with gr.Tab("Enhance"):
414
+ gr.Markdown("### Upscale and sharpen any image 2x or 4x using Real-ESRGAN.")
415
+ with gr.Row(equal_height= True):
416
+ with gr.Column(scale= 1):
417
+ enh_input = gr.Image(label="Upload Image", type="pil", height= 350)
418
+ enh_scale = gr.Radio(
419
+ choices=["2x", "4x"],
420
+ value="4x",
421
+ label="Upscale Factor",
422
+ info="4x recommended for most images. Use 2x for very large inputs."
423
  )
424
+ enh_btn = gr.Button("Enhance", variant="primary", size="lg")
425
+ with gr.Column(scale=1):
426
+ enh_output = gr.Image(label="Result", type="pil", interactive=False, height=350, show_download_button=True,)
427
+ enh_info = gr.Textbox(label="Size Info", interactive=False, container=True,)
428
 
429
  enh_btn.click(fn=enhance_image, inputs=[enh_input, enh_scale], outputs=[enh_output, enh_info])
430
+ #--------Colourize---------------------------
431
  with gr.Tab("Colorize"):
432
+ gr.Markdown("""
433
+ ### B&W Photo Colorization
434
+ DDColor adds natural, realistic colors while preserving the original structure."""
435
  )
436
+ with gr.Row(equal_height= True):
437
+ with gr.Column(scale=1):
438
+ col_input = gr.Image(label="Upload B&W Image", type="pil", height=350)
439
  col_strength = gr.Slider(
440
  minimum=0.5, maximum=1.0, value=0.9, step=0.05,
441
  label="Color Strength",
442
  # BUG 10 FIX: maximum changed from 0.7 to 1.0
443
+ info="0.5 = subtle tint · 1.0 = full vivid color"
 
444
  )
445
+ col_btn = gr.Button("Colorize", variant="primary", size="lg")
446
  with gr.Column():
447
+ col_output = gr.Image(label="Colorized Result", type="pil", interactive=False, height=350,
448
+ show_download_button=True,)
449
 
450
  col_btn.click(fn=colour_image, inputs=[col_input, col_strength], outputs=[col_output])
451
+ #----------Outpaint-----------------------------
452
  with gr.Tab("Outpaint"):
453
+ gr.Markdown("""### Extend Any Scene
454
+ Upload an image and extend it in any direction.
455
+ BLIP reads the scene automatically — no prompt needed."""
456
  )
457
+ with gr.Row(equal_height= True):
458
+ with gr.Column(scale= 1):
459
+ out_input = gr.Image(label="Upload Image", type="pil", height=350)
460
  out_dir = gr.Radio(
461
  choices=["Horizontal", "Vertical", "Both"], value="Horizontal",
462
  label="Extension Direction",
463
  info="Horizontal = left & right | Vertical = top & bottom | Both = all sides"
464
  )
465
  out_pct = gr.Slider(minimum=10, maximum=50, value=25, step=5, label="Extend by (%)")
466
+ with gr.Accordion("Advanced: Custom Prompt", open=False):
467
+ # gr.Accordion = collapsible section
468
+ # open=False = collapsed by default keeps UI clean
469
+ # Users who want it can expand, others aren't distracted
470
+ out_prompt = gr.Textbox(
471
+ label="Custom Prompt (optional)",
472
+ placeholder="Leave empty — BLIP reads your image automatically. Or type: 'a forest with tall oak trees'",
473
+ lines=3,
474
+ )
475
+ out_btn = gr.Button("Outpaint", variant="primary", size="lg")
476
+ with gr.Column(scale=1):
477
+ out_output = gr.Image(label="Result", type="pil", interactive=False, height= 350, show_download_button= True)
478
  out_caption = gr.Textbox(label="Prompt Used", interactive=False, lines=4)
479
 
480
  out_btn.click(
 
482
  inputs=[out_input, out_dir, out_pct, out_prompt],
483
  outputs=[out_output, out_caption]
484
  )
485
+ # Footer
486
+ gr.Markdown(
487
+ """
488
+ ---
489
+ Built with Real-ESRGAN · DDColor · Stable Diffusion 2 · BLIP · Gradio
490
+ """
491
+ )
492
+
493
 
494
  demo.launch()