mgbam commited on
Commit
b781adc
Β·
verified Β·
1 Parent(s): 45a73fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -65
app.py CHANGED
@@ -1,79 +1,59 @@
1
  # app.py
2
  import gradio as gr
3
- from genesis.pipeline import research_once, DEMO_QUERIES
 
4
 
 
5
  def run_pipeline_ui(query):
6
- """Run the full GENESIS-AI pipeline for the given query."""
7
  try:
8
- result = research_once(query)
9
-
10
- summary_md = f"### Research Summary\n{result['summary']}"
11
- cites_md = "### Citations\n"
12
- if result["citations"]:
13
- for c in result["citations"]:
14
- cites_md += f"- [{c['type']} {c['id'] or ''}]({c['url']})\n"
15
- else:
16
- cites_md += "_No citations found._"
17
-
18
- struct_md = "### Molecular Structures\n"
19
- if result["structures"]:
20
- for s in result["structures"]:
21
- struct_md += f"- **{s['name']}** β€” [View]({s['url']})\n"
22
- else:
23
- struct_md += "_No structures found._"
24
-
25
- img_md = ""
26
- if result["visual_image_url"]:
27
- img_md = f"### Visual Diagram\n![]({result['visual_image_url']})"
28
-
29
- audio_component = None
30
- if result["audio_url"]:
31
- audio_component = result["audio_url"]
32
-
33
- return summary_md, cites_md, struct_md, img_md, audio_component
34
-
35
  except Exception as e:
36
- return f"**Error:** {e}", "", "", "", None
37
-
38
-
39
- with gr.Blocks(title="GENESIS-AI β€” Synthetic Biology Research Engine", theme="default") as demo:
40
- gr.Markdown("# 🧬 GENESIS-AI β€” Synthetic Biology Research Engine")
41
- gr.Markdown("Ask about synthetic biology, drug design, CRISPR, biosensors, and more.")
42
 
43
- with gr.Row():
44
- query_input = gr.Textbox(label="Enter your research topic", placeholder="e.g., AI-driven biosensor design for early cancer detection")
45
- run_btn = gr.Button("Run Research", variant="primary")
 
 
 
46
 
47
  with gr.Row():
48
- summary_output = gr.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  with gr.Row():
50
- cites_output = gr.Markdown()
51
- with gr.Row():
52
- struct_output = gr.Markdown()
53
- with gr.Row():
54
- img_output = gr.Markdown()
55
- with gr.Row():
56
- audio_output = gr.Audio()
57
-
58
- run_btn.click(
59
- run_pipeline_ui,
60
- inputs=[query_input],
61
- outputs=[summary_output, cites_output, struct_output, img_output, audio_output]
62
- )
63
-
64
- gr.Markdown("## Demo Queries")
65
- demo_gallery = gr.Dataset(
66
- components=[gr.Textbox()],
67
- samples=[[q] for q in DEMO_QUERIES],
68
- type="values",
69
- label="Click a demo query to run it"
70
- )
71
-
72
- demo_gallery.click(
73
- run_pipeline_ui,
74
  inputs=[query_input],
75
- outputs=[summary_output, cites_output, struct_output, img_output, audio_output]
76
  )
77
 
78
  if __name__ == "__main__":
79
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
1
  # app.py
2
  import gradio as gr
3
+ from genesis.pipeline import research_once
4
+ from genesis.pipeline import DEMO_QUERIES
5
 
6
+ # --------- UI Callback ---------
7
  def run_pipeline_ui(query):
 
8
  try:
9
+ report = research_once(query)
10
+ return (
11
+ report["summary"],
12
+ report["citations"],
13
+ report["structures"],
14
+ report["visual_image_url"] or "No image generated",
15
+ report["audio_url"] or None
16
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  except Exception as e:
18
+ return f"Error: {e}", [], [], None, None
 
 
 
 
 
19
 
20
+ # --------- Gradio UI ---------
21
+ with gr.Blocks(title="GENESIS-AI β€” Synthetic Biology Research Engine") as demo:
22
+ gr.Markdown("## 🧬 GENESIS-AI β€” Synthetic Biology Research Engine")
23
+ gr.Markdown(
24
+ "Ask about synthetic biology, drug design, CRISPR, biosensors, and more."
25
+ )
26
 
27
  with gr.Row():
28
+ query_input = gr.Textbox(
29
+ label="Enter your research topic",
30
+ placeholder="e.g., Design a CRISPR-based living therapeutic for triple-negative breast cancer",
31
+ lines=2
32
+ )
33
+ run_button = gr.Button("πŸš€ Run Research", variant="primary")
34
+
35
+ output_summary = gr.Textbox(label="Summary", lines=8)
36
+ output_citations = gr.JSON(label="Citations")
37
+ output_structures = gr.JSON(label="Molecular Structures")
38
+ output_image = gr.Image(label="Generated Diagram / Image")
39
+ output_audio = gr.Audio(label="Narration", type="filepath")
40
+
41
+ # Demo Queries Section
42
+ gr.Markdown("### Demo Queries")
43
  with gr.Row():
44
+ for q in DEMO_QUERIES:
45
+ gr.Button(q).click(
46
+ fn=run_pipeline_ui,
47
+ inputs=[gr.Textbox(value=q, visible=False)],
48
+ outputs=[output_summary, output_citations, output_structures, output_image, output_audio]
49
+ )
50
+
51
+ # Main run button
52
+ run_button.click(
53
+ fn=run_pipeline_ui,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  inputs=[query_input],
55
+ outputs=[output_summary, output_citations, output_structures, output_image, output_audio]
56
  )
57
 
58
  if __name__ == "__main__":
59
+ demo.launch(server_name="0.0.0.0", server_port=7860)