Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 551 |
|
|
|
|
| 552 |
gr.HTML(lamp_html)
|
| 553 |
with gr.Row():
|
| 554 |
gr.Markdown("<h1>πΌοΈ Image Processor</h1>")
|
| 555 |
|
| 556 |
-
|
| 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(
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(
|
| 580 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
height = gr.Number(label="Height (px)", value=1000, precision=0)
|
| 582 |
|
| 583 |
-
|
|
|
|
| 584 |
with gr.Group(elem_classes="panel"):
|
| 585 |
-
status = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
zip_download_btn = gr.Button("π¦ Download ZIP")
|
| 587 |
-
zip_file_hidden
|
| 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
|
| 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 |
-
# βββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|
| 620 |
-
single_downloads, status,
|
|
|
|
| 621 |
]
|
| 622 |
)
|
| 623 |
|
| 624 |
-
stop_btn.click(
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|