mgbam commited on
Commit
7984ae1
Β·
verified Β·
1 Parent(s): 7c3897e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -45
app.py CHANGED
@@ -1,9 +1,12 @@
1
- # app.py
2
  import gradio as gr
 
3
  from genesis.pipeline import research_once
4
- from genesis.molecule_viewer import get_molecule_view
5
 
6
- # Preloaded demo queries for instant wow-factor
 
 
 
 
7
  DEMO_QUERIES = [
8
  "CRISPR living therapeutics in clinical trials since 2020",
9
  "AI-designed enzymes for plastic degradation β€” literature + pathways",
@@ -12,49 +15,67 @@ DEMO_QUERIES = [
12
  "Oncolytic virus engineering β€” biosecurity risk analysis"
13
  ]
14
 
15
- # ---- UI Functions ----
16
- def run_research(query):
17
- result = research_once(query)
18
- return (
19
- result["summary"],
20
- "\n".join([f"{c['type']}: {c['url']}" for c in result["citations"]]),
21
- result["visual_image_url"] or "No image",
22
- result["audio_url"] or "No audio"
23
- )
24
 
25
- def explore_molecule(pdb_or_gene):
26
- return get_molecule_view(pdb_or_gene)
27
 
28
- # ---- UI Layout ----
29
- with gr.Blocks(css=".gradio-container {background-color: #0a0a0a; color: white;}") as demo:
30
- gr.Markdown(
31
- "<h1 style='color:#00ff99;text-shadow:0 0 20px #ff6600;'>🧬 GENESIS-AI: Synthetic Biology Command Center</h1>"
32
- )
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- with gr.Tab("πŸ” Literature & Pathways"):
35
- gr.Markdown("### Select a demo query or enter your own:")
36
- with gr.Row():
 
 
 
 
 
 
 
 
 
37
  for q in DEMO_QUERIES:
38
- gr.Button(q).click(fn=run_research, inputs=[gr.Textbox(value=q)], outputs=[
39
- gr.Textbox(label="Summary"),
40
- gr.Textbox(label="Citations"),
41
- gr.Image(label="Generated Diagram"),
42
- gr.Audio(label="Narrated Summary")
43
- ])
44
-
45
- user_query = gr.Textbox(label="Custom Query")
46
- submit_btn = gr.Button("Run Research")
47
- summary = gr.Textbox(label="Summary")
48
- citations = gr.Textbox(label="Citations")
49
- diagram = gr.Image(label="Generated Diagram")
50
- audio = gr.Audio(label="Narrated Summary")
51
-
52
- submit_btn.click(fn=run_research, inputs=user_query, outputs=[summary, citations, diagram, audio])
53
-
54
- with gr.Tab("πŸ§ͺ 3D Molecule Explorer"):
55
- mol_input = gr.Textbox(label="Enter PDB ID or Gene/Protein Name")
56
- mol_btn = gr.Button("Load Structure")
57
- mol_view = gr.HTML(label="3D Structure")
58
- mol_btn.click(fn=explore_molecule, inputs=mol_input, outputs=mol_view)
59
-
60
- demo.launch()
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
3
  from genesis.pipeline import research_once
 
4
 
5
+ # Load custom biotech theme
6
+ with open("static/style.css", "r") as f:
7
+ custom_css = f.read()
8
+
9
+ # Demo queries to impress the scientific audience
10
  DEMO_QUERIES = [
11
  "CRISPR living therapeutics in clinical trials since 2020",
12
  "AI-designed enzymes for plastic degradation β€” literature + pathways",
 
15
  "Oncolytic virus engineering β€” biosecurity risk analysis"
16
  ]
17
 
18
+ def run_pipeline(query, narration_enabled):
19
+ """Run the research pipeline with optional narration."""
20
+ if not query or query.strip() == "":
21
+ return "Please enter a query.", None, None, None, None
 
 
 
 
 
22
 
23
+ report = research_once(query, narration=narration_enabled)
 
24
 
25
+ summary = report.get("summary", "No summary available.")
26
+ citations = report.get("citations", [])
27
+ structures = report.get("structures", [])
28
+ visual_image_url = report.get("visual_image_url", None)
29
+ audio_url = report.get("audio_url", None)
30
+
31
+ cites_md = ""
32
+ for c in citations:
33
+ cites_md += f"- **{c['type']}**: [{c['id'] or 'link'}]({c['url']})\n"
34
+
35
+ return summary, cites_md, structures, visual_image_url, audio_url
36
+
37
+
38
+ with gr.Blocks(css=custom_css, theme="default") as demo:
39
+ gr.Markdown("# 🧬 GENESIS-AI β€” Synthetic Biology Research Console")
40
+ gr.Markdown("### Explore CRISPR, metabolic engineering, living therapeutics, and beyond β€” powered by AI.")
41
 
42
+ with gr.Row():
43
+ with gr.Column(scale=2):
44
+ query_box = gr.Textbox(
45
+ placeholder="Enter your research question...",
46
+ label="Research Query",
47
+ lines=3
48
+ )
49
+ narration_toggle = gr.Checkbox(label="Enable narration (uses API credits)", value=False)
50
+ run_btn = gr.Button("πŸ” Run Research")
51
+
52
+ gr.Markdown("**Quick Demo Queries**")
53
+ demo_query_buttons = []
54
  for q in DEMO_QUERIES:
55
+ btn = gr.Button(q)
56
+ demo_query_buttons.append((btn, q))
57
+
58
+ with gr.Column(scale=3):
59
+ output_summary = gr.Markdown(label="Research Summary")
60
+ output_citations = gr.Markdown(label="Citations")
61
+ output_structures = gr.JSON(label="Structures Data")
62
+ output_visual = gr.Image(label="Generated Diagram")
63
+ output_audio = gr.Audio(label="Narrated Summary")
64
+
65
+ # Main run button
66
+ run_btn.click(
67
+ fn=run_pipeline,
68
+ inputs=[query_box, narration_toggle],
69
+ outputs=[output_summary, output_citations, output_structures, output_visual, output_audio]
70
+ )
71
+
72
+ # Demo query buttons
73
+ for btn, q in demo_query_buttons:
74
+ btn.click(
75
+ fn=run_pipeline,
76
+ inputs=[gr.Textbox(value=q, visible=False), narration_toggle],
77
+ outputs=[output_summary, output_citations, output_structures, output_visual, output_audio]
78
+ )
79
+
80
+ if __name__ == "__main__":
81
+ demo.launch(server_name="0.0.0.0", server_port=7860)