mgbam commited on
Commit
fdfd8f7
Β·
verified Β·
1 Parent(s): 1415a81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -120
app.py CHANGED
@@ -1,139 +1,91 @@
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
- # Demo queries for fast testing
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
- # Store past results for quick access
16
- history_store = {}
17
-
18
- def run_pipeline(query):
19
- """Run the GENESIS-AI research pipeline and return formatted outputs."""
20
- if not query.strip():
21
- return "⚠️ Please enter a topic", "", None, None, None
22
-
23
  report = research_once(query)
24
- history_store[query] = report # save to session
25
-
26
- # Build citations markdown
27
- cites_md = ""
28
- if report["citations"]:
29
- cites_md = "### πŸ“š Citations\n" + "\n".join(
30
- [f"- [{c['type']}]({c['url']})" for c in report["citations"]]
31
- )
32
- else:
33
- cites_md = "⚠️ _No citations found_"
34
-
35
- # Build pathway & funding visualizations
36
- pathway_fig = generate_pathway_graph(
37
- entities=report["expanded_terms"],
38
- relationships=[{"source": report["expanded_terms"][i],
39
- "target": report["expanded_terms"][i+1],
40
- "type": "related"}
41
- for i in range(len(report["expanded_terms"]) - 1)]
42
- )
43
-
44
- funding_fig = generate_funding_network(
45
- companies=[
46
- {"name": "SynBioTech", "investors": "BioFund, HealthCapital"},
47
- {"name": "GeneWorks", "investors": "BioFund, InnovationAngels"}
48
- ]
49
- )
50
-
51
  return (
52
  report["summary"],
53
- cites_md,
 
54
  report["visual_image_url"],
55
- pathway_fig,
56
- funding_fig
57
  )
58
 
59
- def load_history(query):
60
- """Load past research result instantly."""
61
- report = history_store.get(query)
62
- if not report:
63
- return "", "", None, None, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- cites_md = "### πŸ“š Citations\n" + "\n".join(
66
- [f"- [{c['type']}]({c['url']})" for c in report["citations"]]
67
- )
68
- return (
69
- report["summary"],
70
- cites_md,
71
- report["visual_image_url"],
72
- generate_pathway_graph(
73
- entities=report["expanded_terms"],
74
- relationships=[{"source": report["expanded_terms"][i],
75
- "target": report["expanded_terms"][i+1],
76
- "type": "related"}
77
- for i in range(len(report["expanded_terms"]) - 1)]
78
- ),
79
- generate_funding_network(
80
- companies=[
81
- {"name": "SynBioTech", "investors": "BioFund, HealthCapital"},
82
- {"name": "GeneWorks", "investors": "BioFund, InnovationAngels"}
83
- ]
84
- )
85
- )
86
 
87
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald", secondary_hue="gray")) as demo:
88
- gr.Markdown(
89
- """
90
- # 🌱 **GENESIS-AI** β€” Synthetic Biology Intelligence Platform
91
- _AI-powered research, visualization, and synthesis for the future of life sciences._
92
- """
93
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  with gr.Row():
96
- with gr.Column(scale=3):
97
- query_box = gr.Textbox(
98
- label="πŸ” Enter a research topic",
99
- placeholder="e.g., CRISPR gene therapy for cancer",
100
- lines=2
101
- )
102
- run_btn = gr.Button("πŸš€ Run Research", variant="primary")
103
- gr.Markdown("### πŸ”¬ Quick Research Chips")
104
- with gr.Row():
105
- for q in DEMO_QUERIES:
106
- gr.Button(q, elem_classes="chip").click(
107
- run_pipeline, inputs=gr.Textbox(value=q, visible=False),
108
- outputs=["summary_out", "cites_out", "image_out", "pathway_out", "funding_out"]
109
- )
110
-
111
- gr.Markdown("### πŸ•˜ History")
112
- history_list = gr.Dropdown(
113
- choices=[], label="Past Research Queries", interactive=True
114
- )
115
- history_list.change(
116
- load_history, inputs=history_list,
117
- outputs=["summary_out", "cites_out", "image_out", "pathway_out", "funding_out"]
118
- )
119
-
120
- with gr.Column(scale=7):
121
- with gr.Accordion("πŸ“„ Summary", open=True):
122
- summary_out = gr.Markdown(elem_id="summary_out")
123
- with gr.Accordion("πŸ“š Citations", open=False):
124
- cites_out = gr.Markdown(elem_id="cites_out")
125
- with gr.Accordion("πŸ–ΌοΈ Image / Diagram", open=False):
126
- image_out = gr.Image(type="filepath", elem_id="image_out")
127
- with gr.Accordion("πŸ”— Pathway Graph", open=False):
128
- pathway_out = gr.Plot(elem_id="pathway_out")
129
- with gr.Accordion("πŸ’° Funding Network", open=False):
130
- funding_out = gr.Plot(elem_id="funding_out")
131
-
132
- run_btn.click(
133
- fn=run_pipeline,
134
- inputs=query_box,
135
- outputs=[summary_out, cites_out, image_out, pathway_out, funding_out]
136
  )
137
 
138
- if __name__ == "__main__":
139
- demo.launch()
 
 
1
  import gradio as gr
2
  from genesis.pipeline import research_once
3
  from genesis.visualization import generate_pathway_graph, generate_funding_network
4
 
5
+ # Preloaded killer demo queries
6
  DEMO_QUERIES = [
7
+ "CRISPR living therapeutics in clinical trials since 2020",
8
+ "AI-designed enzymes for plastic degradation β€” literature + pathways",
9
+ "Synthetic biology startups in oncology β€” funding map",
10
+ "Metabolic pathway for artemisinin biosynthesis in yeast",
11
+ "Oncolytic virus engineering β€” biosecurity risk analysis"
12
  ]
13
 
14
+ def run_literature_review(query):
 
 
 
 
 
 
 
15
  report = research_once(query)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  return (
17
  report["summary"],
18
+ report["citations"],
19
+ report["structures"],
20
  report["visual_image_url"],
21
+ report["audio_url"]
 
22
  )
23
 
24
+ def run_pathway_graph():
25
+ entities = ["CRISPR", "Cas9", "DNA Repair", "Therapeutic Delivery"]
26
+ relationships = [
27
+ {"source": "CRISPR", "target": "Cas9", "type": "guides"},
28
+ {"source": "Cas9", "target": "DNA Repair", "type": "triggers"},
29
+ {"source": "DNA Repair", "target": "Therapeutic Delivery", "type": "enables"}
30
+ ]
31
+ return generate_pathway_graph(entities, relationships)
32
+
33
+ def run_funding_network():
34
+ companies = [
35
+ {"name": "SynBioCorp", "investors": "Sequoia Capital, Andreessen Horowitz"},
36
+ {"name": "BioTheraX", "investors": "SoftBank, ARCH Venture Partners"}
37
+ ]
38
+ return generate_funding_network(companies)
39
+
40
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald", secondary_hue="lime")) as app:
41
+ gr.Markdown("# 🧬 GENESIS-AI β€” Synthetic Biology Command Center")
42
+ gr.Markdown("A next-generation **lab instrument** for literature review, pathway mapping, funding analysis, and biosecurity insights.")
43
 
44
+ with gr.Row():
45
+ query_input = gr.Textbox(label="Enter your research query", placeholder="e.g., CRISPR living therapeutics in clinical trials since 2020", lines=2)
46
+ run_button = gr.Button("πŸš€ Run Literature Review", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ gr.Markdown("### πŸ”Ή Or click a demo query:")
49
+ with gr.Row():
50
+ demo_btns = []
51
+ for dq in DEMO_QUERIES:
52
+ btn = gr.Button(dq)
53
+ btn.click(fn=lambda q=dq: run_literature_review(q),
54
+ inputs=[],
55
+ outputs=["summary_box", "citations_box", "structures_box", "image_out", "audio_out"])
56
+ demo_btns.append(btn)
57
+
58
+ with gr.Tab("πŸ“„ Summary"):
59
+ summary_box = gr.Textbox(label="AI-Generated Summary", lines=15, interactive=False)
60
+
61
+ with gr.Tab("πŸ“š Citations"):
62
+ citations_box = gr.JSON(label="Citations")
63
+
64
+ with gr.Tab("πŸ§ͺ Structures"):
65
+ structures_box = gr.JSON(label="3D Molecular Structures")
66
+
67
+ with gr.Tab("πŸ–Ό Diagram"):
68
+ image_out = gr.Image(label="Generated Diagram")
69
+
70
+ with gr.Tab("πŸ”Š Narration"):
71
+ audio_out = gr.Audio(label="Narrated Summary", type="filepath")
72
+
73
+ gr.Markdown("## 🧭 Additional Tools")
74
 
75
  with gr.Row():
76
+ pathway_btn = gr.Button("🧬 Generate Pathway Graph")
77
+ pathway_img = gr.Image(label="Pathway Graph")
78
+ pathway_btn.click(fn=run_pathway_graph, inputs=[], outputs=pathway_img)
79
+
80
+ funding_btn = gr.Button("πŸ’° Generate Funding Network")
81
+ funding_img = gr.Image(label="Funding Network")
82
+ funding_btn.click(fn=run_funding_network, inputs=[], outputs=funding_img)
83
+
84
+ # Link main run button
85
+ run_button.click(
86
+ fn=run_literature_review,
87
+ inputs=query_input,
88
+ outputs=[summary_box, citations_box, structures_box, image_out, audio_out]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  )
90
 
91
+ app.launch()