Spaces:
Sleeping
Sleeping
# 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"\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() | |