Xue-Jun/StructureBasedSimilarityNetwork
0
1import os2 3import gradio as gr4 5from utils import calculate_md5, run_community_analysis, run_usalign, save_pdb_files6 7os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"8 9# Create Gradio interface10with gr.Blocks() as demo:11 gr.Markdown("# This is a Temp Title")12 13 with gr.Row():14 file_input = gr.File(15 label="Upload PDB Files",16 file_count="multiple",17 file_types=[".pdb"],18 )19 20 output = gr.Textbox(21 label="Upload Results", lines=5, max_lines=5, container=True # 默认显示行数 # 最大可见行数(超过后自动滚动)22 )23 24 threshold = gr.Slider(minimum=0, maximum=1, value=0.75, label="Threshold")25 26 with gr.Row():27 28 submit_btn = gr.Button("Upload Files")29 run_usalign_btn = gr.Button("Run USalign")30 community_btn = gr.Button("Run Community")31 32 md5_hash = gr.State("")33 with gr.Tab("USalign Results"):34 results_df = gr.DataFrame(35 label="USalign Results",36 wrap=True,37 )38 with gr.Tab("TM Matrix"):39 # Add new output components for community analysis with height limits40 tm_matrix_output = gr.DataFrame(label="TM Matrix", wrap=True, show_label=True)41 with gr.Tab("Newick Tree"):42 newick_output = gr.Textbox(43 label="Newick Tree", lines=5, max_lines=10, container=True # 默认显示行数 # 最大可见行数(超过后自动滚动)44 )45 # with gr.Tab("Structure Similarity Network"):46 # network_plot = gr.Plot(label="Structure Similarity Network")47 48 # Combine download buttons into a single row49 with gr.Row():50 with gr.Column():51 gr.Markdown("### Download Results")52 download_tm = gr.File(label="Download Files")53 54 submit_btn.click(fn=save_pdb_files, inputs=[file_input], outputs=output)55 56 def update_md5_hash(files):57 if files:58 return calculate_md5(files)59 return ""60 61 file_input.change(fn=update_md5_hash, inputs=[file_input], outputs=[md5_hash])62 63 run_usalign_btn.click(fn=run_usalign, inputs=[md5_hash], outputs=[results_df])64 65 def process_community_analysis(results_df, md5_hash, threshold):66 if results_df.empty:67 return None, None, None68 69 results = run_community_analysis(results_df, "./data", md5_hash, threshold)70 71 if "Error" in results:72 return None, None, None73 74 # Prepare download files75 76 return (77 results["tm_matrix"],78 results["newick_str"],79 # results["network_fig"],80 results["files"],81 )82 83 community_btn.click(84 fn=process_community_analysis,85 inputs=[results_df, md5_hash, threshold],86 outputs=[87 tm_matrix_output,88 newick_output,89 # network_plot,90 download_tm,91 ],92 )93 94if __name__ == "__main__":95 demo.launch(server_name="0.0.0.0")96 