mgbam commited on
Commit
68d6a9c
Β·
verified Β·
1 Parent(s): afd6eb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -45
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
- # 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",
@@ -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 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],
@@ -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"] 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()
 
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()