import os import gradio as gr from genesis.pipeline import ( run_literature_review, run_molecule_lookup, run_pathway_analysis, run_funding_analysis, run_image_analysis ) from genesis.visualization import generate_pathway_graph, generate_funding_network from genesis.utils.pdf_export import export_report_to_pdf # Load custom CSS with open("genesis/static/style.css", "r") as f: custom_css = f.read() # App Title APP_TITLE = "๐Ÿงฌ GENESIS-AI โ€” The Synthetic Biology OS" APP_DESCRIPTION = """ Your **multi-modal synthetic biology intelligence suite**. Explore molecules, pathways, funding, literature, and images โ€” with real-time AI insights. """ # ========================= # TAB FUNCTIONS # ========================= def literature_tab(query): """Run literature review (PubMed, ChEMBL, BioPortal, UMLS)""" summary, citations = run_literature_review(query) pdf_path = export_report_to_pdf( filename="literature_report.pdf", title="Literature Review", summary=summary, citations=citations ) return summary, citations, pdf_path def molecule_tab(molecule_name): """Fetch molecule data from ChEMBL/NCBI & visualize""" mol_data, mol_img = run_molecule_lookup(molecule_name) pdf_path = export_report_to_pdf( filename="molecule_report.pdf", title="Molecule Report", summary=mol_data ) return mol_data, mol_img, pdf_path def pathway_tab(pathway_name): """Run pathway analysis & generate graph""" analysis = run_pathway_analysis(pathway_name) graph_fig = generate_pathway_graph(pathway_name) pdf_path = export_report_to_pdf( filename="pathway_report.pdf", title="Pathway Analysis", summary=analysis ) return analysis, graph_fig, pdf_path def funding_tab(keyword): """Run funding analysis & generate investor graph""" funding_info = run_funding_analysis(keyword) funding_graph = generate_funding_network(keyword) pdf_path = export_report_to_pdf( filename="funding_report.pdf", title="Funding Analysis", summary=funding_info ) return funding_info, funding_graph, pdf_path def image_tab(image_file): """Run microscopy/image analysis""" analysis_text = run_image_analysis(image_file) pdf_path = export_report_to_pdf( filename="image_report.pdf", title="Image Analysis", summary=analysis_text ) return analysis_text, pdf_path # ========================= # GRADIO UI # ========================= with gr.Blocks(css=custom_css, theme="default") as demo: gr.HTML(f"

{APP_TITLE}

{APP_DESCRIPTION}

") with gr.Tabs(): # Literature Tab with gr.Tab("๐Ÿ“š Literature Review"): lit_query = gr.Textbox(label="Enter research question") lit_summary = gr.Textbox(label="Summary", lines=8) lit_citations = gr.Textbox(label="Citations", lines=5) lit_pdf = gr.File(label="Download PDF") lit_btn = gr.Button("Run Literature Review", variant="primary") lit_btn.click(literature_tab, inputs=lit_query, outputs=[lit_summary, lit_citations, lit_pdf]) # Molecule Lookup with gr.Tab("๐Ÿงช Molecule Viewer"): mol_name = gr.Textbox(label="Enter molecule name / ChEMBL ID") mol_info = gr.Textbox(label="Molecule Information", lines=8) mol_img = gr.Image(label="Structure") mol_pdf = gr.File(label="Download PDF") mol_btn = gr.Button("Lookup Molecule", variant="primary") mol_btn.click(molecule_tab, inputs=mol_name, outputs=[mol_info, mol_img, mol_pdf]) # Pathway Analysis with gr.Tab("๐Ÿ”ฌ Pathway Analysis"): path_name = gr.Textbox(label="Enter pathway name") path_analysis = gr.Textbox(label="Pathway Analysis", lines=8) path_graph = gr.Plot(label="Pathway Graph") path_pdf = gr.File(label="Download PDF") path_btn = gr.Button("Analyze Pathway", variant="primary") path_btn.click(pathway_tab, inputs=path_name, outputs=[path_analysis, path_graph, path_pdf]) # Funding Network with gr.Tab("๐Ÿ’ฐ Funding Explorer"): fund_keyword = gr.Textbox(label="Enter biotech keyword") fund_info = gr.Textbox(label="Funding Information", lines=8) fund_graph = gr.Plot(label="Funding Network") fund_pdf = gr.File(label="Download PDF") fund_btn = gr.Button("Analyze Funding", variant="primary") fund_btn.click(funding_tab, inputs=fund_keyword, outputs=[fund_info, fund_graph, fund_pdf]) # Image Analysis with gr.Tab("๐Ÿ–ผ๏ธ Image Analysis"): img_upload = gr.Image(type="filepath", label="Upload microscopy or bio-image") img_analysis = gr.Textbox(label="Image Analysis", lines=8) img_pdf = gr.File(label="Download PDF") img_btn = gr.Button("Analyze Image", variant="primary") img_btn.click(image_tab, inputs=img_upload, outputs=[img_analysis, img_pdf]) demo.queue().launch(server_name="0.0.0.0", server_port=7860)