Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
7 |
DEMO_QUERIES = [
|
8 |
-
"
|
9 |
-
"
|
10 |
-
"Synthetic biology startups
|
11 |
-
"
|
12 |
-
"
|
13 |
]
|
14 |
|
15 |
-
|
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 |
-
|
|
|
54 |
report["visual_image_url"],
|
55 |
-
|
56 |
-
funding_fig
|
57 |
)
|
58 |
|
59 |
-
def
|
60 |
-
"""
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
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 |
-
|
88 |
-
gr.
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
with gr.Row():
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
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 |
-
|
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()
|
|