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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -56
app.py CHANGED
@@ -1,79 +1,79 @@
1
  # app.py
2
- import os
3
  import gradio as gr
4
- from genesis.pipeline import research_once
5
- from genesis.narration import narrate_text
6
 
7
  def run_pipeline_ui(query):
8
- """Run the full synthetic biology research pipeline and handle flexible outputs."""
9
  try:
10
- # Call pipeline
11
- output = research_once(query)
12
-
13
- # Handle cases with more than 5 return values
14
- report = output[0] if len(output) > 0 else "No report generated."
15
- citations = output[1] if len(output) > 1 else []
16
- structures = output[2] if len(output) > 2 else []
17
- graph_status = output[3] if len(output) > 3 else "No graph status."
18
- image_url = output[4] if len(output) > 4 else None
19
 
20
- # Generate narration
21
- audio_path = narrate_text(report) or None
22
-
23
- # Citations
24
  cites_md = "### Citations\n"
25
- if citations:
26
- for cite in citations:
27
- cites_md += f"- [{cite.get('type','Ref')} {cite.get('id','')}]({cite.get('url','#')})\n"
28
  else:
29
- cites_md += "_No citations found._\n"
30
 
31
- # Structures
32
  struct_md = "### Molecular Structures\n"
33
- if structures:
34
- for s in structures:
35
- struct_md += f"- {s.get('term','Unknown')}: [{s.get('pdb_id','')}]({s.get('pdbe_url','#')}) ([RCSB]({s.get('rcsb_url','#')}))\n"
36
  else:
37
- struct_md += "_No structures found._\n"
38
 
39
- # Image
40
- img_md = "### Generated Visual\n"
41
- if image_url:
42
- img_md += f"![Diagram]({image_url})\n"
43
- else:
44
- img_md += "_No visual generated._\n"
45
 
46
- return report, cites_md, struct_md, graph_status, audio_path, img_md
 
 
 
 
47
 
48
  except Exception as e:
49
- return f"Error: {str(e)}", "", "", "", None, ""
 
 
 
 
 
50
 
51
- # Gradio UI
52
- with gr.Blocks(title="GENESIS-AI: Synthetic Biology Deep Research") as demo:
53
- gr.Markdown("# 🧬 GENESIS-AI\nThe most advanced synthetic biology research assistant ever built.")
54
-
55
  with gr.Row():
56
- query_box = gr.Textbox(label="Enter a Research Topic", placeholder="e.g. CRISPR-based probiotics for cancer therapy")
57
- run_btn = gr.Button("πŸš€ Run Research", variant="primary")
58
 
59
- with gr.Tab("πŸ“„ Report"):
60
- report_out = gr.Textbox(label="Full Research Report", lines=20)
61
- with gr.Tab("πŸ“š Citations"):
62
- cites_out = gr.Markdown()
63
- with gr.Tab("πŸ”¬ Structures"):
64
- struct_out = gr.Markdown()
65
- with gr.Tab("πŸ•Έ Graph"):
66
- graph_status_out = gr.Textbox(label="Graph DB Status")
67
- with gr.Tab("πŸ”Š Narration"):
68
- audio_out = gr.Audio(label="Narrated Summary")
69
- with gr.Tab("πŸ–Ό Visual Diagram"):
70
- img_out = gr.Markdown()
71
 
72
  run_btn.click(
73
- fn=run_pipeline_ui,
74
- inputs=[query_box],
75
- outputs=[report_out, cites_out, struct_out, graph_status_out, audio_out, img_out]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  )
77
 
78
  if __name__ == "__main__":
79
- demo.launch()
 
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)