Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ 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 |
"Map all CRISPR-based living therapeutics in clinical trials since 2020",
|
9 |
"Graph metabolic engineering pathways for bio-based drug production",
|
@@ -12,19 +12,27 @@ DEMO_QUERIES = [
|
|
12 |
"AI-driven biosensor design for early cancer detection"
|
13 |
]
|
14 |
|
|
|
|
|
|
|
15 |
def run_pipeline(query):
|
16 |
-
"""Run GENESIS-AI pipeline and return
|
|
|
|
|
|
|
17 |
report = research_once(query)
|
|
|
18 |
|
19 |
-
#
|
20 |
-
cites_md = "
|
21 |
if report["citations"]:
|
22 |
-
|
23 |
-
|
|
|
24 |
else:
|
25 |
-
cites_md
|
26 |
|
27 |
-
# Build pathway
|
28 |
pathway_fig = generate_pathway_graph(
|
29 |
entities=report["expanded_terms"],
|
30 |
relationships=[{"source": report["expanded_terms"][i],
|
@@ -33,7 +41,6 @@ def run_pipeline(query):
|
|
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"},
|
@@ -44,52 +51,89 @@ def run_pipeline(query):
|
|
44 |
return (
|
45 |
report["summary"],
|
46 |
cites_md,
|
47 |
-
report["visual_image_url"]
|
48 |
pathway_fig,
|
49 |
funding_fig
|
50 |
)
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
gr.Markdown("### Quick Demo Queries")
|
62 |
with gr.Row():
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
run_btn.click(
|
81 |
fn=run_pipeline,
|
82 |
-
inputs=
|
83 |
-
outputs=[
|
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()
|
|
|
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",
|
|
|
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],
|
|
|
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"},
|
|
|
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()
|