mgbam's picture
Update app.py
0f230a9 verified
raw
history blame
2.89 kB
# app.py
import os
import gradio as gr
from genesis.pipeline import research_once
from genesis.narration import narrate_text
def run_pipeline_ui(query):
"""Run the full synthetic biology research pipeline and handle flexible outputs."""
try:
# Call pipeline
output = research_once(query)
# Handle cases with more than 5 return values
report = output[0] if len(output) > 0 else "No report generated."
citations = output[1] if len(output) > 1 else []
structures = output[2] if len(output) > 2 else []
graph_status = output[3] if len(output) > 3 else "No graph status."
image_url = output[4] if len(output) > 4 else None
# Generate narration
audio_path = narrate_text(report) or None
# Citations
cites_md = "### Citations\n"
if citations:
for cite in citations:
cites_md += f"- [{cite.get('type','Ref')} {cite.get('id','')}]({cite.get('url','#')})\n"
else:
cites_md += "_No citations found._\n"
# Structures
struct_md = "### Molecular Structures\n"
if structures:
for s in structures:
struct_md += f"- {s.get('term','Unknown')}: [{s.get('pdb_id','')}]({s.get('pdbe_url','#')}) ([RCSB]({s.get('rcsb_url','#')}))\n"
else:
struct_md += "_No structures found._\n"
# Image
img_md = "### Generated Visual\n"
if image_url:
img_md += f"![Diagram]({image_url})\n"
else:
img_md += "_No visual generated._\n"
return report, cites_md, struct_md, graph_status, audio_path, img_md
except Exception as e:
return f"Error: {str(e)}", "", "", "", None, ""
# Gradio UI
with gr.Blocks(title="GENESIS-AI: Synthetic Biology Deep Research") as demo:
gr.Markdown("# 🧬 GENESIS-AI\nThe most advanced synthetic biology research assistant ever built.")
with gr.Row():
query_box = gr.Textbox(label="Enter a Research Topic", placeholder="e.g. CRISPR-based probiotics for cancer therapy")
run_btn = gr.Button("πŸš€ Run Research", variant="primary")
with gr.Tab("πŸ“„ Report"):
report_out = gr.Textbox(label="Full Research Report", lines=20)
with gr.Tab("πŸ“š Citations"):
cites_out = gr.Markdown()
with gr.Tab("πŸ”¬ Structures"):
struct_out = gr.Markdown()
with gr.Tab("πŸ•Έ Graph"):
graph_status_out = gr.Textbox(label="Graph DB Status")
with gr.Tab("πŸ”Š Narration"):
audio_out = gr.Audio(label="Narrated Summary")
with gr.Tab("πŸ–Ό Visual Diagram"):
img_out = gr.Markdown()
run_btn.click(
fn=run_pipeline_ui,
inputs=[query_box],
outputs=[report_out, cites_out, struct_out, graph_status_out, audio_out, img_out]
)
if __name__ == "__main__":
demo.launch()