Workpam commited on
Commit
d42e9bc
Β·
verified Β·
1 Parent(s): 76cde08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -28
app.py CHANGED
@@ -546,55 +546,95 @@ gr.HTML("""
546
  """)
547
 
548
  with gr.Blocks(css=css) as demo:
 
549
  image_data_state = gr.State([])
550
- temp_dir_state = gr.State(None)
551
 
 
552
  gr.HTML(lamp_html)
553
  with gr.Row():
554
  gr.Markdown("<h1>πŸ–ΌοΈ Image Processor</h1>")
555
 
556
- # ─────── LEFT PANEL ───────
557
  with gr.Row():
 
558
  with gr.Column(scale=3, min_width=500):
559
  with gr.Group(elem_classes="panel"):
560
- mode_toggle = gr.Radio(["πŸ“„ Upload Workbook", "πŸ“€ Upload Images"], value="πŸ“„ Upload Workbook", label="Select Input Method")
561
- workbook_upload = gr.File(label="πŸ“‚ Upload .xlsx/.xlsm Workbook", file_types=['.xlsx', '.xlsm'], visible=True)
562
- upload_box = gr.File(label="πŸ“ Upload Images", file_count="multiple", visible=False)
563
- image_url_input = gr.Textbox( label="🌐 Paste Image URL", visible=False)
564
-
565
- def toggle_inputs(choice):
566
- is_wb = choice.startswith("πŸ“„")
567
- return (
568
- gr.update(visible=is_wb),
569
- gr.update(visible=not is_wb),
570
- gr.update(visible=not is_wb)
571
- )
572
-
573
- mode_toggle.change( fn=toggle_inputs, inputs=[mode_toggle], outputs=[workbook_upload, upload_box, image_url_input] )
574
- upload_box.change( lambda files: f"{len(files)} files ready." if files else "No files selected",inputs=[upload_box], outputs=[status] )
 
 
 
 
575
  process_btn = gr.Button("βš™οΈ Process", elem_id="process-btn-url")
576
 
577
  with gr.Group(elem_classes="panel"):
578
  with gr.Row():
579
- format_choice = gr.Dropdown(["JPEG","PNG","WEBP","TIFF","GIF","JFIF","AVIF"],label="πŸ–ΌοΈ Format", value="JPEG")
580
- width = gr.Number(label="Width (px)", value=1000, precision=0)
 
 
 
 
581
  height = gr.Number(label="Height (px)", value=1000, precision=0)
582
 
583
- with gr.Column(scale=2):
 
584
  with gr.Group(elem_classes="panel"):
585
- status = gr.Textbox(label="πŸ“£ Status", lines=6, interactive=False, elem_id="status-box")
 
 
 
 
 
586
  zip_download_btn = gr.Button("πŸ“¦ Download ZIP")
587
- zip_file_hidden = gr.File(visible=False)
588
  with gr.Accordion("🧷 Individual Files", open=False):
589
  single_downloads = gr.File(label="Files", file_count="multiple")
590
 
591
  with gr.Row(elem_classes="btn-row"):
592
- stop_btn = gr.Button("Stop", elem_id="stop-btn")
593
  clear_btn = gr.Button("Clear", elem_id="clear-btn")
594
 
 
595
  gr.Markdown("<center style='margin-top:1rem;color:white'>Created with πŸ’œ by Vishakha</center>")
596
 
597
- # ─────── HOOK UP EVENTS ───────
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  process_btn.click(
599
  fn=lambda mode, sd, ups, pu, fmt, w, h: (
600
  process_url_images(sd, fmt, w, h) if mode.startswith("πŸ“„") and sd else
@@ -609,19 +649,24 @@ with gr.Blocks(css=css) as demo:
609
  zip_download_btn.click(
610
  None,
611
  inputs=[zip_file_hidden],
612
- js="(file) => file && window.open(file.url)"
613
  )
614
 
615
  clear_btn.click(
616
  fn=clear_all,
617
  inputs=[temp_dir_state],
618
  outputs=[
619
- workbook_upload, image_data_state, upload_box, zip_file_hidden,
620
- single_downloads, status, temp_dir_state, image_url_input
 
621
  ]
622
  )
623
 
624
- stop_btn.click(lambda: ("πŸ›‘ Stop signal sent",), outputs=[status])
 
 
 
625
 
626
  if __name__ == "__main__":
627
  demo.queue().launch(debug=True)
 
 
546
  """)
547
 
548
  with gr.Blocks(css=css) as demo:
549
+ # ─── States ───
550
  image_data_state = gr.State([])
551
+ temp_dir_state = gr.State(None)
552
 
553
+ # ─── Header ───
554
  gr.HTML(lamp_html)
555
  with gr.Row():
556
  gr.Markdown("<h1>πŸ–ΌοΈ Image Processor</h1>")
557
 
558
+ # ─── Main layout ───
559
  with gr.Row():
560
+ # ── LEFT PANEL ──
561
  with gr.Column(scale=3, min_width=500):
562
  with gr.Group(elem_classes="panel"):
563
+ mode_toggle = gr.Radio(
564
+ ["πŸ“„ Upload Workbook", "πŸ“€ Upload Images"],
565
+ value="πŸ“„ Upload Workbook",
566
+ label="Select Input Method"
567
+ )
568
+ workbook_upload = gr.File(
569
+ label="πŸ“‚ Upload .xlsx/.xlsm Workbook",
570
+ file_types=['.xlsx', '.xlsm'],
571
+ visible=True
572
+ )
573
+ upload_box = gr.File(
574
+ label="πŸ“ Upload Images",
575
+ file_count="multiple",
576
+ visible=False
577
+ )
578
+ image_url_input = gr.Textbox(
579
+ label="🌐 Paste Image URL",
580
+ visible=False
581
+ )
582
  process_btn = gr.Button("βš™οΈ Process", elem_id="process-btn-url")
583
 
584
  with gr.Group(elem_classes="panel"):
585
  with gr.Row():
586
+ format_choice = gr.Dropdown(
587
+ ["JPEG","PNG","WEBP","TIFF","GIF","JFIF","AVIF"],
588
+ label="πŸ–ΌοΈ Format",
589
+ value="JPEG"
590
+ )
591
+ width = gr.Number(label="Width (px)", value=1000, precision=0)
592
  height = gr.Number(label="Height (px)", value=1000, precision=0)
593
 
594
+ # ── RIGHT PANEL ──
595
+ with gr.Column(scale=2, min_width=400):
596
  with gr.Group(elem_classes="panel"):
597
+ status = gr.Textbox(
598
+ label="πŸ“£ Status",
599
+ lines=6,
600
+ interactive=False,
601
+ elem_id="status-box"
602
+ )
603
  zip_download_btn = gr.Button("πŸ“¦ Download ZIP")
604
+ zip_file_hidden = gr.File(visible=False)
605
  with gr.Accordion("🧷 Individual Files", open=False):
606
  single_downloads = gr.File(label="Files", file_count="multiple")
607
 
608
  with gr.Row(elem_classes="btn-row"):
609
+ stop_btn = gr.Button("Stop", elem_id="stop-btn")
610
  clear_btn = gr.Button("Clear", elem_id="clear-btn")
611
 
612
+ # ─── Footer ───
613
  gr.Markdown("<center style='margin-top:1rem;color:white'>Created with πŸ’œ by Vishakha</center>")
614
 
615
+ # ─── EVENT HOOKS ───
616
+ mode_toggle.change(
617
+ fn=lambda choice: (
618
+ gr.update(visible=choice.startswith("πŸ“„")),
619
+ gr.update(visible=not choice.startswith("πŸ“„")),
620
+ gr.update(visible=not choice.startswith("πŸ“„"))
621
+ ),
622
+ inputs=[mode_toggle],
623
+ outputs=[workbook_upload, upload_box, image_url_input]
624
+ )
625
+
626
+ workbook_upload.change(
627
+ fn=read_uploaded_workbook,
628
+ inputs=[workbook_upload],
629
+ outputs=[image_data_state, status]
630
+ )
631
+
632
+ upload_box.change(
633
+ fn=lambda files: f"{len(files)} files ready." if files else "No files selected",
634
+ inputs=[upload_box],
635
+ outputs=[status]
636
+ )
637
+
638
  process_btn.click(
639
  fn=lambda mode, sd, ups, pu, fmt, w, h: (
640
  process_url_images(sd, fmt, w, h) if mode.startswith("πŸ“„") and sd else
 
649
  zip_download_btn.click(
650
  None,
651
  inputs=[zip_file_hidden],
652
+ js="(file) => file && window.open(file.url, '_blank')"
653
  )
654
 
655
  clear_btn.click(
656
  fn=clear_all,
657
  inputs=[temp_dir_state],
658
  outputs=[
659
+ workbook_upload, image_data_state, upload_box,
660
+ zip_file_hidden, single_downloads, status,
661
+ temp_dir_state, image_url_input
662
  ]
663
  )
664
 
665
+ stop_btn.click(
666
+ fn=lambda: "πŸ›‘ Stop signal sent",
667
+ outputs=[status]
668
+ )
669
 
670
  if __name__ == "__main__":
671
  demo.queue().launch(debug=True)
672
+