| import os |
|
|
| import gradio as gr |
|
|
| from utils import calculate_md5, run_community_analysis, run_usalign, save_pdb_files |
|
|
| os.environ["GRADIO_ANALYTICS_ENABLED"] = "False" |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("# This is a Temp Title") |
|
|
| with gr.Row(): |
| file_input = gr.File( |
| label="Upload PDB Files", |
| file_count="multiple", |
| file_types=[".pdb"], |
| ) |
|
|
| output = gr.Textbox( |
| label="Upload Results", lines=5, max_lines=5, container=True |
| ) |
|
|
| threshold = gr.Slider(minimum=0, maximum=1, value=0.75, label="Threshold") |
|
|
| with gr.Row(): |
|
|
| submit_btn = gr.Button("Upload Files") |
| run_usalign_btn = gr.Button("Run USalign") |
| community_btn = gr.Button("Run Community") |
|
|
| md5_hash = gr.State("") |
| with gr.Tab("USalign Results"): |
| results_df = gr.DataFrame( |
| label="USalign Results", |
| wrap=True, |
| ) |
| with gr.Tab("TM Matrix"): |
| |
| tm_matrix_output = gr.DataFrame(label="TM Matrix", wrap=True, show_label=True) |
| with gr.Tab("Newick Tree"): |
| newick_output = gr.Textbox( |
| label="Newick Tree", lines=5, max_lines=10, container=True |
| ) |
| |
| |
|
|
| |
| with gr.Row(): |
| with gr.Column(): |
| gr.Markdown("### Download Results") |
| download_tm = gr.File(label="Download Files") |
|
|
| submit_btn.click(fn=save_pdb_files, inputs=[file_input], outputs=output) |
|
|
| def update_md5_hash(files): |
| if files: |
| return calculate_md5(files) |
| return "" |
|
|
| file_input.change(fn=update_md5_hash, inputs=[file_input], outputs=[md5_hash]) |
|
|
| run_usalign_btn.click(fn=run_usalign, inputs=[md5_hash], outputs=[results_df]) |
|
|
| def process_community_analysis(results_df, md5_hash, threshold): |
| if results_df.empty: |
| return None, None, None |
|
|
| results = run_community_analysis(results_df, "./data", md5_hash, threshold) |
|
|
| if "Error" in results: |
| return None, None, None |
|
|
| |
|
|
| return ( |
| results["tm_matrix"], |
| results["newick_str"], |
| |
| results["files"], |
| ) |
|
|
| community_btn.click( |
| fn=process_community_analysis, |
| inputs=[results_df, md5_hash, threshold], |
| outputs=[ |
| tm_matrix_output, |
| newick_output, |
| |
| download_tm, |
| ], |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch(server_name="0.0.0.0") |
|
|