Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,42 +20,42 @@ with open("mtdna_tool_explainer_updated.html", "r", encoding="utf-8") as f:
|
|
| 20 |
flow_chart = f.read()
|
| 21 |
|
| 22 |
# This would go in a separate CSS file or a <style> block in your Gradio app
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
with gr.Blocks() as interface:
|
| 61 |
# with gr.Tab("CURIOUS ABOUT THIS PRODUCT?"):
|
|
@@ -63,7 +63,15 @@ with gr.Blocks() as interface:
|
|
| 63 |
with gr.Tab("𧬠Classifier"):
|
| 64 |
gr.Markdown("# 𧬠mtDNA Location Classifier (MVP)")
|
| 65 |
#inputMode = gr.Radio(choices=["Single Accession", "Batch Input"], value="Single Accession", label="Choose Input Mode")
|
| 66 |
-
user_email = gr.Textbox(label="π§ Your email (used to track free quota)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
usage_display = gr.Markdown("", visible=False)
|
| 68 |
|
| 69 |
# with gr.Group() as single_input_group:
|
|
@@ -77,7 +85,7 @@ with gr.Blocks() as interface:
|
|
| 77 |
# file_upload = gr.File(label="π Or Upload CSV/Excel File", file_types=[".csv", ".xlsx"], interactive=True, elem_id="file-upload-box")
|
| 78 |
raw_text = gr.Textbox(label="π§ Input Accession Number(s) (single (KU131308) or comma-separated (e.g., MF362736.1,MF362738.1,KU131308,MW291678))")
|
| 79 |
#resume_file = gr.File(label="ποΈ Previously saved Excel output (optional)", file_types=[".xlsx"], interactive=True)
|
| 80 |
-
gr.HTML("""<a href="https://docs.google.com/spreadsheets/d/1lKqPp17EfHsshJGZRWEpcNOZlGo3F5qU/edit?usp=sharing" download target="_blank">
|
| 81 |
file_upload = gr.File(label="π Or Upload CSV/Excel File", file_types=[".csv", ".xlsx"], interactive=True)
|
| 82 |
processed_info = gr.Markdown(visible=False) # new placeholder for processed list
|
| 83 |
|
|
@@ -159,7 +167,10 @@ with gr.Blocks() as interface:
|
|
| 159 |
# return gr.update(visible=True), gr.update(visible=False)
|
| 160 |
# else:
|
| 161 |
# return gr.update(visible=False), gr.update(visible=True)
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
def classify_with_loading():
|
| 164 |
return gr.update(value="β³ Please wait... processing...",visible=True) # Show processing message
|
| 165 |
|
|
@@ -566,7 +577,7 @@ with gr.Blocks() as interface:
|
|
| 566 |
warning = f"β οΈ Only processing first {limited_acc} accessions."
|
| 567 |
else:
|
| 568 |
warning = f"β
All {total} accessions will be processed."
|
| 569 |
-
processed_info = warning + "\n" +f"Processed
|
| 570 |
### NEW: Hide inputs, show processed_info at start
|
| 571 |
yield (
|
| 572 |
make_html_table(all_rows), # output_table
|
|
@@ -578,8 +589,8 @@ with gr.Blocks() as interface:
|
|
| 578 |
gr.update(visible=False), # run_button,
|
| 579 |
gr.update(visible=True), # show stop button
|
| 580 |
gr.update(visible=True), # show reset button
|
| 581 |
-
gr.update(visible=
|
| 582 |
-
gr.update(visible=
|
| 583 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 584 |
gr.update(visible=False) # hide NPS modal at start
|
| 585 |
)
|
|
@@ -673,8 +684,8 @@ with gr.Blocks() as interface:
|
|
| 673 |
gr.update(visible=False), # run_button
|
| 674 |
gr.update(visible=False), # stop_button
|
| 675 |
gr.update(visible=True), # reset_button
|
| 676 |
-
gr.update(visible=
|
| 677 |
-
gr.update(visible=
|
| 678 |
gr.update(value=processed_info, visible=False), # processed_info
|
| 679 |
gr.update(visible=True) # NPS modal now visible
|
| 680 |
)
|
|
@@ -701,8 +712,8 @@ with gr.Blocks() as interface:
|
|
| 701 |
gr.update(visible=False), # run_button
|
| 702 |
gr.update(visible=True), # stop_button
|
| 703 |
gr.update(visible=True), # reset_button
|
| 704 |
-
gr.update(visible=
|
| 705 |
-
gr.update(visible=
|
| 706 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 707 |
gr.update(visible=False) # hide NPS modal at start
|
| 708 |
)
|
|
@@ -739,8 +750,8 @@ with gr.Blocks() as interface:
|
|
| 739 |
gr.update(visible=False), # run_button
|
| 740 |
gr.update(visible=True), # stop_button
|
| 741 |
gr.update(visible=True), # reset_button
|
| 742 |
-
gr.update(visible=
|
| 743 |
-
gr.update(visible=
|
| 744 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 745 |
gr.update(visible=False) # hide NPS modal
|
| 746 |
)
|
|
@@ -774,8 +785,8 @@ with gr.Blocks() as interface:
|
|
| 774 |
gr.update(visible=False), # run_button
|
| 775 |
gr.update(visible=False), # stop_button
|
| 776 |
gr.update(visible=True), # reset_button
|
| 777 |
-
gr.update(visible=
|
| 778 |
-
gr.update(visible=
|
| 779 |
gr.update(value="", visible=False), # processed_info
|
| 780 |
gr.update(visible=True) # NPS modal now visible
|
| 781 |
)
|
|
@@ -810,11 +821,11 @@ with gr.Blocks() as interface:
|
|
| 810 |
"", # usage_display
|
| 811 |
"β³ Processing...", # status
|
| 812 |
"\n".join(log_lines), # progress_box
|
| 813 |
-
gr.update(visible=
|
| 814 |
gr.update(visible=True), # stop_button
|
| 815 |
gr.update(visible=True), # reset_button
|
| 816 |
-
gr.update(visible=
|
| 817 |
-
gr.update(visible=
|
| 818 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 819 |
gr.update(visible=False) # hide NPS modal at start
|
| 820 |
)
|
|
@@ -829,11 +840,11 @@ with gr.Blocks() as interface:
|
|
| 829 |
"", # usage_display
|
| 830 |
"β³ Processing...", # status
|
| 831 |
"\n".join(log_lines), # progress_box
|
| 832 |
-
gr.update(visible=
|
| 833 |
gr.update(visible=True), # stop_button
|
| 834 |
gr.update(visible=True), # reset_button
|
| 835 |
-
gr.update(visible=
|
| 836 |
-
gr.update(visible=
|
| 837 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 838 |
gr.update(visible=False) # hide NPS modal at start
|
| 839 |
)
|
|
@@ -868,8 +879,8 @@ with gr.Blocks() as interface:
|
|
| 868 |
gr.update(visible=False), # run_button
|
| 869 |
gr.update(visible=False), # stop_button
|
| 870 |
gr.update(visible=True), # reset_button
|
| 871 |
-
gr.update(visible=
|
| 872 |
-
gr.update(visible=
|
| 873 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 874 |
gr.update(visible=True) # NPS modal now visible
|
| 875 |
)
|
|
@@ -1104,6 +1115,12 @@ with gr.Blocks() as interface:
|
|
| 1104 |
# queue=True, # β
ensure the queue is used
|
| 1105 |
# #every=0.5
|
| 1106 |
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1107 |
run_button.click(
|
| 1108 |
fn=threaded_batch_runner,
|
| 1109 |
inputs=[file_upload, raw_text, user_email],
|
|
|
|
| 20 |
flow_chart = f.read()
|
| 21 |
|
| 22 |
# This would go in a separate CSS file or a <style> block in your Gradio app
|
| 23 |
+
css = """
|
| 24 |
+
#nps-buttons-container .gr-radio-group {
|
| 25 |
+
display: flex;
|
| 26 |
+
flex-direction: row;
|
| 27 |
+
justify-content: center;
|
| 28 |
+
gap: 8px; /* Adjust spacing between buttons */
|
| 29 |
+
}
|
| 30 |
+
#nps-buttons-container .gr-radio-input {
|
| 31 |
+
display: none; /* Hide the default radio circle */
|
| 32 |
+
}
|
| 33 |
+
#nps-buttons-container .gr-radio-label {
|
| 34 |
+
display: flex;
|
| 35 |
+
justify-content: center;
|
| 36 |
+
align-items: center;
|
| 37 |
+
width: 40px; /* Adjust button size */
|
| 38 |
+
height: 40px;
|
| 39 |
+
border-radius: 8px; /* Adjust border radius for rounded corners */
|
| 40 |
+
background-color: #38a169; /* Example green color */
|
| 41 |
+
color: white;
|
| 42 |
+
font-weight: bold;
|
| 43 |
+
cursor: pointer;
|
| 44 |
+
transition: background-color 0.2s ease;
|
| 45 |
+
}
|
| 46 |
+
#nps-buttons-container .gr-radio-label:hover {
|
| 47 |
+
background-color: #2f855a; /* Darker green on hover */
|
| 48 |
+
}
|
| 49 |
+
#nps-buttons-container input[type="radio"]:checked + .gr-radio-label {
|
| 50 |
+
background-color: #1a4f35; /* Even darker green for the selected state */
|
| 51 |
+
border: 2px solid white; /* Highlight the selected button */
|
| 52 |
+
}
|
| 53 |
+
#nps-left-label, #nps-right-label {
|
| 54 |
+
width: 50%;
|
| 55 |
+
font-size: 0.9em;
|
| 56 |
+
color: #666;
|
| 57 |
+
}
|
| 58 |
+
"""
|
| 59 |
|
| 60 |
with gr.Blocks() as interface:
|
| 61 |
# with gr.Tab("CURIOUS ABOUT THIS PRODUCT?"):
|
|
|
|
| 63 |
with gr.Tab("𧬠Classifier"):
|
| 64 |
gr.Markdown("# 𧬠mtDNA Location Classifier (MVP)")
|
| 65 |
#inputMode = gr.Radio(choices=["Single Accession", "Batch Input"], value="Single Accession", label="Choose Input Mode")
|
| 66 |
+
#user_email = gr.Textbox(label="π§ Your email (used to track free quota)")
|
| 67 |
+
|
| 68 |
+
sign_in_button = gr.Button("Sign in to Download")
|
| 69 |
+
user_email = gr.Textbox(
|
| 70 |
+
label="π§ Your email (used to track free quota)",
|
| 71 |
+
visible=False
|
| 72 |
+
)
|
| 73 |
+
# The output will be used to display a message to the user
|
| 74 |
+
output_message = gr.Textbox(visible=False, interactive=False)
|
| 75 |
usage_display = gr.Markdown("", visible=False)
|
| 76 |
|
| 77 |
# with gr.Group() as single_input_group:
|
|
|
|
| 85 |
# file_upload = gr.File(label="π Or Upload CSV/Excel File", file_types=[".csv", ".xlsx"], interactive=True, elem_id="file-upload-box")
|
| 86 |
raw_text = gr.Textbox(label="π§ Input Accession Number(s) (single (KU131308) or comma-separated (e.g., MF362736.1,MF362738.1,KU131308,MW291678))")
|
| 87 |
#resume_file = gr.File(label="ποΈ Previously saved Excel output (optional)", file_types=[".xlsx"], interactive=True)
|
| 88 |
+
gr.HTML("""<a href="https://docs.google.com/spreadsheets/d/1lKqPp17EfHsshJGZRWEpcNOZlGo3F5qU/edit?usp=sharing" download target="_blank">Example Excel Batch Input Format</a>""")
|
| 89 |
file_upload = gr.File(label="π Or Upload CSV/Excel File", file_types=[".csv", ".xlsx"], interactive=True)
|
| 90 |
processed_info = gr.Markdown(visible=False) # new placeholder for processed list
|
| 91 |
|
|
|
|
| 167 |
# return gr.update(visible=True), gr.update(visible=False)
|
| 168 |
# else:
|
| 169 |
# return gr.update(visible=False), gr.update(visible=True)
|
| 170 |
+
def show_email_textbox():
|
| 171 |
+
# Return a gr.update() to make the textbox visible and set the message
|
| 172 |
+
return gr.update(visible=True), gr.update(value="Give your email to download excel output and 20+ more free samples", visible=True)
|
| 173 |
+
|
| 174 |
def classify_with_loading():
|
| 175 |
return gr.update(value="β³ Please wait... processing...",visible=True) # Show processing message
|
| 176 |
|
|
|
|
| 577 |
warning = f"β οΈ Only processing first {limited_acc} accessions."
|
| 578 |
else:
|
| 579 |
warning = f"β
All {total} accessions will be processed."
|
| 580 |
+
processed_info = warning + "\n" +f"Processed accessions: {accessions[0]}...{accessions[-1]}"
|
| 581 |
### NEW: Hide inputs, show processed_info at start
|
| 582 |
yield (
|
| 583 |
make_html_table(all_rows), # output_table
|
|
|
|
| 589 |
gr.update(visible=False), # run_button,
|
| 590 |
gr.update(visible=True), # show stop button
|
| 591 |
gr.update(visible=True), # show reset button
|
| 592 |
+
gr.update(visible=True), # hide raw_text
|
| 593 |
+
gr.update(visible=True), # hide file_upload
|
| 594 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 595 |
gr.update(visible=False) # hide NPS modal at start
|
| 596 |
)
|
|
|
|
| 684 |
gr.update(visible=False), # run_button
|
| 685 |
gr.update(visible=False), # stop_button
|
| 686 |
gr.update(visible=True), # reset_button
|
| 687 |
+
gr.update(visible=True), # raw_text
|
| 688 |
+
gr.update(visible=True), # file_upload
|
| 689 |
gr.update(value=processed_info, visible=False), # processed_info
|
| 690 |
gr.update(visible=True) # NPS modal now visible
|
| 691 |
)
|
|
|
|
| 712 |
gr.update(visible=False), # run_button
|
| 713 |
gr.update(visible=True), # stop_button
|
| 714 |
gr.update(visible=True), # reset_button
|
| 715 |
+
gr.update(visible=True), # hide raw_text
|
| 716 |
+
gr.update(visible=True), # hide file_upload
|
| 717 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 718 |
gr.update(visible=False) # hide NPS modal at start
|
| 719 |
)
|
|
|
|
| 750 |
gr.update(visible=False), # run_button
|
| 751 |
gr.update(visible=True), # stop_button
|
| 752 |
gr.update(visible=True), # reset_button
|
| 753 |
+
gr.update(visible=True), # raw_text
|
| 754 |
+
gr.update(visible=True), # file_upload
|
| 755 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 756 |
gr.update(visible=False) # hide NPS modal
|
| 757 |
)
|
|
|
|
| 785 |
gr.update(visible=False), # run_button
|
| 786 |
gr.update(visible=False), # stop_button
|
| 787 |
gr.update(visible=True), # reset_button
|
| 788 |
+
gr.update(visible=True), # raw_text
|
| 789 |
+
gr.update(visible=True), # file_upload
|
| 790 |
gr.update(value="", visible=False), # processed_info
|
| 791 |
gr.update(visible=True) # NPS modal now visible
|
| 792 |
)
|
|
|
|
| 821 |
"", # usage_display
|
| 822 |
"β³ Processing...", # status
|
| 823 |
"\n".join(log_lines), # progress_box
|
| 824 |
+
gr.update(visible=False), # run_button
|
| 825 |
gr.update(visible=True), # stop_button
|
| 826 |
gr.update(visible=True), # reset_button
|
| 827 |
+
gr.update(visible=True), # hide raw_text
|
| 828 |
+
gr.update(visible=True), # hide file_upload
|
| 829 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 830 |
gr.update(visible=False) # hide NPS modal at start
|
| 831 |
)
|
|
|
|
| 840 |
"", # usage_display
|
| 841 |
"β³ Processing...", # status
|
| 842 |
"\n".join(log_lines), # progress_box
|
| 843 |
+
gr.update(visible=False), # run_button
|
| 844 |
gr.update(visible=True), # stop_button
|
| 845 |
gr.update(visible=True), # reset_button
|
| 846 |
+
gr.update(visible=True), # hide raw_text
|
| 847 |
+
gr.update(visible=True), # hide file_upload
|
| 848 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 849 |
gr.update(visible=False) # hide NPS modal at start
|
| 850 |
)
|
|
|
|
| 879 |
gr.update(visible=False), # run_button
|
| 880 |
gr.update(visible=False), # stop_button
|
| 881 |
gr.update(visible=True), # reset_button
|
| 882 |
+
gr.update(visible=True), # raw_text
|
| 883 |
+
gr.update(visible=True), # file_upload
|
| 884 |
gr.update(value=processed_info, visible=True), # processed_info
|
| 885 |
gr.update(visible=True) # NPS modal now visible
|
| 886 |
)
|
|
|
|
| 1115 |
# queue=True, # β
ensure the queue is used
|
| 1116 |
# #every=0.5
|
| 1117 |
# )
|
| 1118 |
+
# Link the button to the function
|
| 1119 |
+
sign_in_button.click(
|
| 1120 |
+
fn=show_email_textbox,
|
| 1121 |
+
outputs=[user_email, output_message] # The outputs are the components to be updated
|
| 1122 |
+
)
|
| 1123 |
+
|
| 1124 |
run_button.click(
|
| 1125 |
fn=threaded_batch_runner,
|
| 1126 |
inputs=[file_upload, raw_text, user_email],
|