# app.py import os import gradio as gr from genesis.pipeline import ( run_literature_mode, run_molecule_mode, run_pathway_mode, run_funding_mode, run_image_mode ) from genesis.utils.pdf_export import export_pdf_report # Load CSS with open(os.path.join("genesis", "static", "style.css"), "r") as f: custom_css = f.read() HF_SPACE = os.environ.get("HF_SPACE", "false").lower() == "true" # --------------------------------------------------------- # Wrappers to ensure click-to-run functionality # --------------------------------------------------------- def literature_tab(query, narration, export_pdf): result = run_literature_mode(query, narration=narration) pdf_path = None if export_pdf: pdf_path = export_pdf_report(result) return ( result.get("summary", ""), result.get("citations", []), result.get("visuals", None), result.get("audio_url", None), pdf_path ) def molecule_tab(identifier, narration, export_pdf): result = run_molecule_mode(identifier, narration=narration) pdf_path = None if export_pdf: pdf_path = export_pdf_report(result) return ( result.get("summary", ""), result.get("structure_3d", None), result.get("properties", ""), result.get("audio_url", None), pdf_path ) def pathway_tab(pathway_name, narration, export_pdf): result = run_pathway_mode(pathway_name, narration=narration) pdf_path = None if export_pdf: pdf_path = export_pdf_report(result) return ( result.get("summary", ""), result.get("graph_svg", None), result.get("analysis", ""), result.get("audio_url", None), pdf_path ) def funding_tab(query, narration, export_pdf): result = run_funding_mode(query, narration=narration) pdf_path = None if export_pdf: pdf_path = export_pdf_report(result) return ( result.get("summary", ""), result.get("funding_graph", None), result.get("top_investors", ""), result.get("audio_url", None), pdf_path ) def image_tab(image, narration, export_pdf): result = run_image_mode(image, narration=narration) pdf_path = None if export_pdf: pdf_path = export_pdf_report(result) return ( result.get("summary", ""), result.get("annotations", None), result.get("enhanced_image", None), result.get("audio_url", None), pdf_path ) # --------------------------------------------------------- # Build Gradio Interface # --------------------------------------------------------- with gr.Blocks(css=custom_css, theme=gr.themes.Monochrome()) as demo: gr.Markdown("# ๐Ÿงฌ GENESIS-AI โ€” The Synthetic Biology OS") gr.Markdown("Multi-modal AI for Literature, Molecules, Pathways, Funding, and Images.") with gr.Tab("๐Ÿ“š Literature Review"): with gr.Row(): query = gr.Textbox(label="Research Query") narration = gr.Checkbox(label="Enable Narration", value=False) export_pdf = gr.Checkbox(label="Export PDF", value=False) run_btn = gr.Button("Run Literature Review ๐Ÿš€") summary = gr.Textbox(label="Summary", lines=10) citations = gr.JSON(label="Citations") visuals = gr.Image(label="Visuals") audio_url = gr.Audio(label="Narration Audio") pdf_out = gr.File(label="Download PDF") run_btn.click( literature_tab, inputs=[query, narration, export_pdf], outputs=[summary, citations, visuals, audio_url, pdf_out] ) with gr.Tab("๐Ÿงช Molecule Explorer"): identifier = gr.Textbox(label="Molecule Name / Gene ID") narration2 = gr.Checkbox(label="Enable Narration", value=False) export_pdf2 = gr.Checkbox(label="Export PDF", value=False) run_btn2 = gr.Button("Run Molecule Analysis ๐Ÿ”") summary2 = gr.Textbox(label="Summary", lines=10) structure_3d = gr.HTML(label="3D Structure Viewer") properties = gr.Textbox(label="Properties") audio_url2 = gr.Audio(label="Narration Audio") pdf_out2 = gr.File(label="Download PDF") run_btn2.click( molecule_tab, inputs=[identifier, narration2, export_pdf2], outputs=[summary2, structure_3d, properties, audio_url2, pdf_out2] ) with gr.Tab("๐Ÿงฌ Pathway Mapper"): pathway_name = gr.Textbox(label="Pathway Name") narration3 = gr.Checkbox(label="Enable Narration", value=False) export_pdf3 = gr.Checkbox(label="Export PDF", value=False) run_btn3 = gr.Button("Run Pathway Mapping ๐Ÿงฉ") summary3 = gr.Textbox(label="Summary", lines=10) graph_svg = gr.HTML(label="Pathway Graph") analysis = gr.Textbox(label="Analysis") audio_url3 = gr.Audio(label="Narration Audio") pdf_out3 = gr.File(label="Download PDF") run_btn3.click( pathway_tab, inputs=[pathway_name, narration3, export_pdf3], outputs=[summary3, graph_svg, analysis, audio_url3, pdf_out3] ) with gr.Tab("๐Ÿ’ฐ Funding Network"): funding_query = gr.Textbox(label="Funding Query (global)") narration4 = gr.Checkbox(label="Enable Narration", value=False) export_pdf4 = gr.Checkbox(label="Export PDF", value=False) run_btn4 = gr.Button("Run Funding Analysis ๐ŸŒ") summary4 = gr.Textbox(label="Summary", lines=10) funding_graph = gr.HTML(label="Funding Network Graph") top_investors = gr.Textbox(label="Top Investors") audio_url4 = gr.Audio(label="Narration Audio") pdf_out4 = gr.File(label="Download PDF") run_btn4.click( funding_tab, inputs=[funding_query, narration4, export_pdf4], outputs=[summary4, funding_graph, top_investors, audio_url4, pdf_out4] ) with gr.Tab("๐Ÿ–ผ๏ธ Image Analysis"): img_input = gr.Image(type="filepath", label="Upload Microscopy or Diagram") narration5 = gr.Checkbox(label="Enable Narration", value=False) export_pdf5 = gr.Checkbox(label="Export PDF", value=False) run_btn5 = gr.Button("Run Image Analysis ๐Ÿ–ผ๏ธ") summary5 = gr.Textbox(label="Summary", lines=10) annotations = gr.Image(label="Annotated Image") enhanced_image = gr.Image(label="Enhanced Image") audio_url5 = gr.Audio(label="Narration Audio") pdf_out5 = gr.File(label="Download PDF") run_btn5.click( image_tab, inputs=[img_input, narration5, export_pdf5], outputs=[summary5, annotations, enhanced_image, audio_url5, pdf_out5] ) # --------------------------------------------------------- # Launch # --------------------------------------------------------- if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860, share=HF_SPACE)