Workpam commited on
Commit
8b5355c
Β·
verified Β·
1 Parent(s): fb811b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -80
app.py CHANGED
@@ -544,88 +544,75 @@ gr.HTML("""
544
  </div>
545
  </div>
546
  """)
547
- with gr.Blocks(css=css) as demo:
548
- image_data_state = gr.State([])
549
- temp_dir_state = gr.State(None)
550
-
551
- gr.HTML(lamp_html)
552
-
553
- with gr.Row():
554
- gr.Markdown("<h1>πŸ–ΌοΈ Image Processor</h1>")
555
-
556
- with gr.Row():
557
- with gr.Column(scale=3):
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
- def debug_read_uploaded(file):
595
- data, msg = read_uploaded_workbook(file)
596
- print("Fetched data from Excel:", data[:3]) # Just print a few
597
- return data, msg
598
-
599
- workbook_upload.change(
600
- fn=debug_read_uploaded,
601
- inputs=[workbook_upload],
602
- outputs=[image_data_state, status]
603
- )
604
-
605
- upload_box.change(
606
- lambda files: f"{len(files)} files ready." if files else "No files selected",
607
- [upload_box],
608
- [status]
609
- )
610
-
611
- with gr.Group(elem_classes="panel"):
612
- format_choice = gr.Dropdown(
613
- ["JPEG", "PNG", "WEBP", "TIFF", "GIF", "JFIF", "AVIF"],
614
- label="πŸ–ΌοΈ Format", value="JPEG", scale=1
615
- )
616
- width = gr.Number(label=" Width (px)", value=1000, precision=0, scale=1)
617
- height = gr.Number(label=" Height (px)", value=1000, precision=0, scale=1)
618
-
619
- with gr.Column(scale=2):
620
- with gr.Group(elem_classes="panel"):
621
- zip_download_btn = gr.Button("πŸ“¦ Download ZIP")
622
- zip_file_hidden = gr.File(visible=False)
623
- with gr.Accordion("🧷 Individual Files", open=False):
624
- single_downloads = gr.File(label="Files", file_count="multiple")
625
-
626
- with gr.Row(elem_classes="btn-row"):
627
- stop_btn = gr.Button("Stop", elem_id="stop-btn")
628
- clear_btn = gr.Button("Clear", elem_id="clear-btn")
629
 
630
  gr.Markdown("<center style='margin-top:1rem;color:white'>Created with πŸ’œ by Vishakha</center>")
631
 
 
544
  </div>
545
  </div>
546
  """)
547
+ with gr.Row():
548
+ with gr.Column(scale=1, min_width=450): # Input/controls
549
+ with gr.Group(elem_classes="panel"):
550
+ mode_toggle = gr.Radio(
551
+ ["πŸ“„ Upload Workbook", "πŸ“€ Upload Images"],
552
+ value="πŸ“„ Upload Workbook",
553
+ label="Select Input Method"
554
+ )
555
+
556
+ workbook_upload = gr.File(
557
+ label="πŸ“‚ Upload .xlsx/.xlsm Workbook",
558
+ file_types=['.xlsx', '.xlsm'],
559
+ visible=True
560
+ )
561
+ status = gr.Textbox(
562
+ label="πŸ“£ Status", lines=6, interactive=False, elem_id="status-box"
563
+ )
564
+
565
+ upload_box = gr.File(
566
+ label="πŸ“ Upload Images", file_count="multiple", visible=False
567
+ )
568
+ image_url_input = gr.Textbox(
569
+ label="🌐 Paste Image URL", visible=False
570
+ )
571
+
572
+ def toggle_inputs(choice):
573
+ is_workbook = choice.startswith("πŸ“„")
574
+ return (
575
+ gr.update(visible=is_workbook),
576
+ gr.update(visible=not is_workbook),
577
+ gr.update(visible=not is_workbook)
578
  )
579
 
580
+ mode_toggle.change(
581
+ fn=toggle_inputs,
582
+ inputs=[mode_toggle],
583
+ outputs=[workbook_upload, upload_box, image_url_input]
584
+ )
585
+
586
+ workbook_upload.change(
587
+ fn=read_uploaded_workbook,
588
+ inputs=[workbook_upload],
589
+ outputs=[image_data_state, status]
590
+ )
591
+
592
+ upload_box.change(
593
+ lambda files: f"{len(files)} files ready." if files else "No files selected",
594
+ [upload_box],
595
+ [status]
596
+ )
597
+
598
+ with gr.Group(elem_classes="panel"):
599
+ format_choice = gr.Dropdown(
600
+ ["JPEG", "PNG", "WEBP", "TIFF", "GIF", "JFIF", "AVIF"],
601
+ label="πŸ–ΌοΈ Format", value="JPEG", scale=1
602
+ )
603
+ width = gr.Number(label=" Width (px)", value=1000, precision=0, scale=1)
604
+ height = gr.Number(label=" Height (px)", value=1000, precision=0, scale=1)
605
+
606
+ with gr.Column(scale=1, min_width=450): # Output/results
607
+ with gr.Group(elem_classes="panel"):
608
+ zip_download_btn = gr.Button("πŸ“¦ Download ZIP")
609
+ zip_file_hidden = gr.File(visible=False)
610
+ with gr.Accordion("🧷 Individual Files", open=False):
611
+ single_downloads = gr.File(label="Files", file_count="multiple")
612
+
613
+ with gr.Row(elem_classes="btn-row"):
614
+ stop_btn = gr.Button("Stop", elem_id="stop-btn")
615
+ clear_btn = gr.Button("Clear", elem_id="clear-btn")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
 
617
  gr.Markdown("<center style='margin-top:1rem;color:white'>Created with πŸ’œ by Vishakha</center>")
618