mgbam commited on
Commit
45f823c
Β·
verified Β·
1 Parent(s): 4a97024

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -29
app.py CHANGED
@@ -1,42 +1,95 @@
 
1
  import gradio as gr
2
- from genesis.pipeline import research_once, DEMO_QUERIES
 
3
 
4
- def run_pipeline_ui(query):
5
- """Run the full synthetic biology research pipeline."""
6
- if not query.strip():
7
- return "Please enter a research topic.", "", None, None
 
 
 
 
 
 
 
8
  report = research_once(query)
9
- summary = report["summary"]
10
- citations_md = "\n".join(f"- [{c['type']}]({c['url']})" for c in report["citations"]) or "No citations found."
11
- return summary, citations_md, report["visual_image_url"], report["audio_url"]
12
 
13
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="blue")) as demo:
 
 
 
 
 
 
14
 
15
- gr.Markdown("# 🧬 GENESIS-AI β€” Synthetic Biology Research Engine")
 
 
 
 
 
 
 
16
 
17
- with gr.Row():
18
- query_box = gr.Textbox(label="Enter Your Research Topic", scale=4)
19
- run_btn = gr.Button("πŸš€ Run Research", variant="primary", scale=1)
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- gr.Markdown("**Or try one of these demo queries:**")
 
 
 
22
 
23
- # Outputs (must be defined before using in button.click)
24
- summary_out = gr.Textbox(label="Executive Summary", lines=15, interactive=False)
25
- cites_out = gr.Markdown()
26
- img_out = gr.Image(type="filepath", label="Generated Research Diagram")
27
- audio_out = gr.Audio(type="filepath", label="AI Narration")
28
 
29
- # Create clickable buttons for demo queries
30
  with gr.Row():
 
31
  for q in DEMO_QUERIES:
32
- btn = gr.Button(q)
33
- btn.click(fn=run_pipeline_ui,
34
- inputs=gr.Textbox(value=q, visible=False),
35
- outputs=[summary_out, cites_out, img_out, audio_out])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- # Main run button
38
- run_btn.click(fn=run_pipeline_ui,
39
- inputs=query_box,
40
- outputs=[summary_out, cites_out, img_out, audio_out])
 
 
 
41
 
42
- demo.launch()
 
 
1
+ # app.py
2
  import gradio as gr
3
+ from genesis.pipeline import research_once
4
+ from genesis.visualization import generate_pathway_graph, generate_funding_network
5
 
6
+ # Predefined demo queries
7
+ DEMO_QUERIES = [
8
+ "Map all CRISPR-based living therapeutics in clinical trials since 2020",
9
+ "Graph metabolic engineering pathways for bio-based drug production",
10
+ "Synthetic biology startups developing oncolytic viruses β€” funding + trials",
11
+ "3D bioprinting advances for organ transplantation with regulatory analysis",
12
+ "AI-driven biosensor design for early cancer detection"
13
+ ]
14
+
15
+ def run_pipeline(query):
16
+ """Run GENESIS-AI pipeline and return all outputs for UI."""
17
  report = research_once(query)
 
 
 
18
 
19
+ # Markdown citations
20
+ cites_md = "### Citations\n"
21
+ if report["citations"]:
22
+ for c in report["citations"]:
23
+ cites_md += f"- [{c['type']}]({c['url']})\n"
24
+ else:
25
+ cites_md += "_No citations found_"
26
 
27
+ # Build pathway graph (demo: using expanded_terms as nodes)
28
+ pathway_fig = generate_pathway_graph(
29
+ entities=report["expanded_terms"],
30
+ relationships=[{"source": report["expanded_terms"][i],
31
+ "target": report["expanded_terms"][i+1],
32
+ "type": "related"}
33
+ for i in range(len(report["expanded_terms"]) - 1)]
34
+ )
35
 
36
+ # Funding graph (only demo; in real use, use data from pipeline)
37
+ funding_fig = generate_funding_network(
38
+ companies=[
39
+ {"name": "SynBioTech", "investors": "BioFund, HealthCapital"},
40
+ {"name": "GeneWorks", "investors": "BioFund, InnovationAngels"}
41
+ ]
42
+ )
43
+
44
+ return (
45
+ report["summary"],
46
+ cites_md,
47
+ report["visual_image_url"] or "No image generated",
48
+ pathway_fig,
49
+ funding_fig
50
+ )
51
 
52
+ # ---- Build UI ----
53
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
54
+ gr.Markdown("# 🌱 GENESIS-AI β€” Synthetic Biology Intelligence Platform")
55
+ gr.Markdown("Cutting-edge research synthesis, citations, structures, and interactive graphs.")
56
 
57
+ with gr.Row():
58
+ query_input = gr.Textbox(label="Enter your research topic", placeholder="e.g., CRISPR gene therapy for cancer")
59
+ run_btn = gr.Button("Run Research", variant="primary")
 
 
60
 
61
+ gr.Markdown("### Quick Demo Queries")
62
  with gr.Row():
63
+ demo_buttons = []
64
  for q in DEMO_QUERIES:
65
+ btn = gr.Button(q, variant="secondary")
66
+ demo_buttons.append((btn, q))
67
+
68
+ with gr.Tab("Summary"):
69
+ summary_output = gr.Markdown()
70
+ with gr.Tab("Citations"):
71
+ cites_output = gr.Markdown()
72
+ with gr.Tab("Image / Diagram"):
73
+ image_output = gr.Image(type="filepath")
74
+ with gr.Tab("Pathway Graph"):
75
+ pathway_output = gr.Plot()
76
+ with gr.Tab("Funding Network"):
77
+ funding_output = gr.Plot()
78
+
79
+ # Link run button
80
+ run_btn.click(
81
+ fn=run_pipeline,
82
+ inputs=query_input,
83
+ outputs=[summary_output, cites_output, image_output, pathway_output, funding_output]
84
+ )
85
 
86
+ # Link each demo query button
87
+ for btn, q in demo_buttons:
88
+ btn.click(
89
+ fn=run_pipeline,
90
+ inputs=gr.Textbox(value=q, visible=False),
91
+ outputs=[summary_output, cites_output, image_output, pathway_output, funding_output]
92
+ )
93
 
94
+ if __name__ == "__main__":
95
+ demo.launch()