Workpam commited on
Commit
d4e6f8a
Β·
verified Β·
1 Parent(s): f4a1477

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -67
app.py CHANGED
@@ -556,72 +556,72 @@ with gr.Blocks(css=css) as demo:
556
  with gr.Row():
557
  with gr.Column(scale=1, min_width=450): # Input/controls
558
  with gr.Group(elem_classes="panel"):
559
- mode_toggle = gr.Radio(
560
- ["πŸ“„ Upload Workbook", "πŸ“€ Upload Images"],
561
- value="πŸ“„ Upload Workbook",
562
- label="Select Input Method"
563
- )
564
-
565
- workbook_upload = gr.File(
566
- label="πŸ“‚ Upload .xlsx/.xlsm Workbook",
567
- file_types=['.xlsx', '.xlsm'],
568
- visible=True
569
- )
570
- status = gr.Textbox(
571
- label="πŸ“£ Status", lines=6, interactive=False, elem_id="status-box"
572
- )
573
-
574
- upload_box = gr.File(
575
- label="πŸ“ Upload Images", file_count="multiple", visible=False
576
- )
577
- image_url_input = gr.Textbox(
578
- label="🌐 Paste Image URL", visible=False
579
- )
580
-
581
- def toggle_inputs(choice):
582
- is_workbook = choice.startswith("πŸ“„")
583
- return (
584
- gr.update(visible=is_workbook),
585
- gr.update(visible=not is_workbook),
586
- gr.update(visible=not is_workbook)
587
  )
588
 
589
- mode_toggle.change(
590
- fn=toggle_inputs,
591
- inputs=[mode_toggle],
592
- outputs=[workbook_upload, upload_box, image_url_input]
593
- )
594
-
595
- workbook_upload.change(
596
- fn=read_uploaded_workbook,
597
- inputs=[workbook_upload],
598
- outputs=[image_data_state, status]
599
- )
600
-
601
- upload_box.change(
602
- lambda files: f"{len(files)} files ready." if files else "No files selected",
603
- [upload_box],
604
- [status]
605
- )
606
-
607
- with gr.Group(elem_classes="panel"):
608
- format_choice = gr.Dropdown(
609
- ["JPEG", "PNG", "WEBP", "TIFF", "GIF", "JFIF", "AVIF"],
610
- label="πŸ–ΌοΈ Format", value="JPEG", scale=1
611
- )
612
- width = gr.Number(label=" Width (px)", value=1000, precision=0, scale=1)
613
- height = gr.Number(label=" Height (px)", value=1000, precision=0, scale=1)
614
-
615
- with gr.Column(scale=1, min_width=450): # Output/results
616
- with gr.Group(elem_classes="panel"):
617
- zip_download_btn = gr.Button("πŸ“¦ Download ZIP")
618
- zip_file_hidden = gr.File(visible=False)
619
- with gr.Accordion("🧷 Individual Files", open=False):
620
- single_downloads = gr.File(label="Files", file_count="multiple")
621
-
622
- with gr.Row(elem_classes="btn-row"):
623
- stop_btn = gr.Button("Stop", elem_id="stop-btn")
624
- clear_btn = gr.Button("Clear", elem_id="clear-btn")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
 
626
  gr.Markdown("<center style='margin-top:1rem;color:white'>Created with πŸ’œ by Vishakha</center>")
627
 
@@ -648,11 +648,11 @@ with gr.Blocks(css=css) as demo:
648
  shutil.rmtree(tmp_dir)
649
  return "", [], [], gr.update(visible=False), [], "Cleared.", None, ""
650
 
651
- clear_btn.click(
652
  clear_all,
653
  [temp_dir_state],
654
  [
655
- workbook_input,
656
  image_data_state,
657
  upload_box,
658
  zip_file_hidden,
@@ -671,4 +671,3 @@ with gr.Blocks(css=css) as demo:
671
 
672
  if __name__ == "__main__":
673
  demo.queue().launch(debug=True)
674
-
 
556
  with gr.Row():
557
  with gr.Column(scale=1, min_width=450): # Input/controls
558
  with gr.Group(elem_classes="panel"):
559
+ mode_toggle = gr.Radio(
560
+ ["πŸ“„ Upload Workbook", "πŸ“€ Upload Images"],
561
+ value="πŸ“„ Upload Workbook",
562
+ label="Select Input Method"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  )
564
 
565
+ workbook_upload = gr.File(
566
+ label="πŸ“‚ Upload .xlsx/.xlsm Workbook",
567
+ file_types=['.xlsx', '.xlsm'],
568
+ visible=True
569
+ )
570
+ status = gr.Textbox(
571
+ label="πŸ“£ Status", lines=6, interactive=False, elem_id="status-box"
572
+ )
573
+
574
+ upload_box = gr.File(
575
+ label="πŸ“ Upload Images", file_count="multiple", visible=False
576
+ )
577
+ image_url_input = gr.Textbox(
578
+ label="🌐 Paste Image URL", visible=False
579
+ )
580
+
581
+ def toggle_inputs(choice):
582
+ is_workbook = choice.startswith("πŸ“„")
583
+ return (
584
+ gr.update(visible=is_workbook),
585
+ gr.update(visible=not is_workbook),
586
+ gr.update(visible=not is_workbook)
587
+ )
588
+
589
+ mode_toggle.change(
590
+ fn=toggle_inputs,
591
+ inputs=[mode_toggle],
592
+ outputs=[workbook_upload, upload_box, image_url_input]
593
+ )
594
+
595
+ workbook_upload.change(
596
+ fn=read_uploaded_workbook,
597
+ inputs=[workbook_upload],
598
+ outputs=[image_data_state, status]
599
+ )
600
+
601
+ upload_box.change(
602
+ lambda files: f"{len(files)} files ready." if files else "No files selected",
603
+ [upload_box],
604
+ [status]
605
+ )
606
+
607
+ with gr.Group(elem_classes="panel"):
608
+ format_choice = gr.Dropdown(
609
+ ["JPEG", "PNG", "WEBP", "TIFF", "GIF", "JFIF", "AVIF"],
610
+ label="πŸ–ΌοΈ Format", value="JPEG", scale=1
611
+ )
612
+ width = gr.Number(label=" Width (px)", value=1000, precision=0, scale=1)
613
+ height = gr.Number(label=" Height (px)", value=1000, precision=0, scale=1)
614
+
615
+ with gr.Column(scale=1, min_width=450): # Output/results
616
+ with gr.Group(elem_classes="panel"):
617
+ zip_download_btn = gr.Button("πŸ“¦ Download ZIP")
618
+ zip_file_hidden = gr.File(visible=False)
619
+ with gr.Accordion("🧷 Individual Files", open=False):
620
+ single_downloads = gr.File(label="Files", file_count="multiple")
621
+
622
+ with gr.Row(elem_classes="btn-row"):
623
+ stop_btn = gr.Button("Stop", elem_id="stop-btn")
624
+ clear_btn = gr.Button("Clear", elem_id="clear-btn")
625
 
626
  gr.Markdown("<center style='margin-top:1rem;color:white'>Created with πŸ’œ by Vishakha</center>")
627
 
 
648
  shutil.rmtree(tmp_dir)
649
  return "", [], [], gr.update(visible=False), [], "Cleared.", None, ""
650
 
651
+ clear_btn.click(
652
  clear_all,
653
  [temp_dir_state],
654
  [
655
+ workbook_upload,
656
  image_data_state,
657
  upload_box,
658
  zip_file_hidden,
 
671
 
672
  if __name__ == "__main__":
673
  demo.queue().launch(debug=True)