mgbam commited on
Commit
0f230a9
Β·
verified Β·
1 Parent(s): 7ca7dca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -25
app.py CHANGED
@@ -1,46 +1,60 @@
1
  # app.py
2
  import os
3
  import gradio as gr
4
-
5
  from genesis.pipeline import research_once
6
  from genesis.narration import narrate_text
7
 
8
- # Preloaded demo queries for tomorrow
9
- demo_queries = [
10
- "Designing synthetic gene circuits for targeted cancer therapy",
11
- "CRISPR-based microbial engineering for biofuel production",
12
- "Synthetic biology approaches to carbon capture and sequestration",
13
- "Engineering probiotics for mental health treatments",
14
- "DNA-based nanorobots for targeted drug delivery"
15
- ]
16
-
17
  def run_pipeline_ui(query):
18
- """Run the full synthetic biology research pipeline."""
19
- report, citations, structures, graph_status, image_url = research_once(query)
 
 
 
 
 
 
 
 
 
20
 
21
- audio_path = narrate_text(report) or "Narration not available"
 
22
 
23
- cites_md = "### Citations\n"
24
- for cite in citations:
25
- cites_md += f"- [{cite['type']} {cite['id']}]({cite['url']})\n"
 
 
 
 
26
 
27
- struct_md = "### Molecular Structures\n"
28
- for s in structures:
29
- struct_md += f"- {s['term']}: [{s['pdb_id']}]({s['pdbe_url']}) ([RCSB]({s['rcsb_url']}))\n"
 
 
 
 
30
 
31
- img_md = "### Generated Visual\n"
32
- if image_url:
33
- img_md += f"![Diagram]({image_url})\n"
 
 
 
34
 
35
- return report, cites_md, struct_md, graph_status, audio_path, img_md
36
 
 
 
37
 
 
38
  with gr.Blocks(title="GENESIS-AI: Synthetic Biology Deep Research") as demo:
39
  gr.Markdown("# 🧬 GENESIS-AI\nThe most advanced synthetic biology research assistant ever built.")
40
 
41
  with gr.Row():
42
- query_box = gr.Dropdown(choices=demo_queries, label="Select a Research Topic", value=demo_queries[0])
43
- run_btn = gr.Button("πŸš€ Run Research")
44
 
45
  with gr.Tab("πŸ“„ Report"):
46
  report_out = gr.Textbox(label="Full Research Report", lines=20)
 
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)