mgbam commited on
Commit
e589553
Β·
verified Β·
1 Parent(s): f063cde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +169 -99
app.py CHANGED
@@ -1,110 +1,180 @@
 
1
  import os
2
  import gradio as gr
3
- from genesis.pipeline import research_once
4
- from genesis.visualization import generate_pathway_graph, generate_funding_network
5
-
6
- # Environment variables
7
- OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
8
- ELEVEN_LABS_API_KEY = os.getenv("ELEVEN_LABS_API_KEY")
9
-
10
- # Preloaded demo queries
11
- DEMO_QUERIES = [
12
- "CRISPR living therapeutics in clinical trials since 2020",
13
- "AI-designed enzymes for plastic degradation β€” literature + pathways",
14
- "Synthetic biology startups in oncology β€” funding map",
15
- "Metabolic pathway for artemisinin biosynthesis in yeast",
16
- "Oncolytic virus engineering β€” biosecurity risk analysis"
17
- ]
18
-
19
- # Custom LCARS biotech theme
20
- CUSTOM_CSS = """
21
- body {background-color: #001f1f; color: #ccffcc;}
22
- .gradio-container {font-family: 'Orbitron', sans-serif;}
23
- button {background-color: #ff6600 !important; color: white !important;}
24
- textarea, input {background-color: #003333; color: #ccffcc;}
25
- .tab-nav {background-color: #004d4d !important;}
26
- """
 
 
 
 
 
 
 
27
 
28
- # -------------------- UI Functions -------------------- #
29
- def run_text_query(query, narration):
30
- result = research_once(query, narration=narration)
 
 
31
  return (
32
- result["summary"],
33
- format_citations(result["citations"]),
34
- result["visual_image_url"],
35
- result["structures"],
36
- result["audio_url"] if narration else None
37
  )
38
 
39
- def run_pathway_query(pathway_name):
40
- return generate_pathway_graph(pathway_name)
 
 
 
 
 
 
 
 
 
 
41
 
42
- def run_funding_query(topic):
43
- return generate_funding_network(topic)
 
 
 
 
 
 
 
 
 
 
44
 
45
- def format_citations(citations):
46
- if not citations:
47
- return "No citations found."
48
- md = ""
49
- for cite in citations:
50
- md += f"- [{cite['type']}]({cite['url']})\n"
51
- return md
 
 
 
 
 
52
 
53
- # -------------------- Build UI -------------------- #
54
- with gr.Blocks(css=CUSTOM_CSS, theme="default") as demo:
55
- gr.Markdown("# 🧬 GENESIS-AI β€” Synthetic Biology Command Center")
56
- gr.Markdown("**Multi-modal AI platform linking molecules, pathways, funding, and regulations**")
 
 
57
 
58
- with gr.Tabs():
59
- # ---------- TEXT QUERY TAB ----------
60
- with gr.Tab("πŸ“œ Literature & Regulatory Analysis"):
61
  narration = gr.Checkbox(label="Enable Narration", value=False)
62
- text_input = gr.Textbox(label="Enter your query", placeholder="Type your synthetic biology research question...")
63
- run_btn = gr.Button("Run Research")
64
-
65
- demo_btns = gr.Row()
66
- for q in DEMO_QUERIES:
67
- demo_btns.add(gr.Button(q))
68
-
69
- summary_out = gr.Textbox(label="Summary")
70
- cites_out = gr.Markdown()
71
- img_out = gr.Image(label="Generated Diagram")
72
- struct_out = gr.JSON(label="Molecular Structures")
73
- audio_out = gr.Audio(label="Narration", type="filepath")
74
-
75
- run_btn.click(
76
- fn=run_text_query,
77
- inputs=[text_input, narration],
78
- outputs=[summary_out, cites_out, img_out, struct_out, audio_out]
79
- )
80
-
81
- for q in DEMO_QUERIES:
82
- demo_btns.children[DEMO_QUERIES.index(q)].click(
83
- fn=run_text_query,
84
- inputs=[gr.Textbox(value=q, visible=False), narration],
85
- outputs=[summary_out, cites_out, img_out, struct_out, audio_out]
86
- )
87
-
88
- # ---------- PATHWAY TAB ----------
89
- with gr.Tab("πŸ§ͺ Metabolic Pathway Mapping"):
90
- pathway_input = gr.Textbox(label="Pathway Name", placeholder="e.g., artemisinin biosynthesis")
91
- pathway_btn = gr.Button("Generate Pathway Graph")
92
- pathway_graph_out = gr.Image(label="Pathway Graph")
93
- pathway_btn.click(run_pathway_query, inputs=pathway_input, outputs=pathway_graph_out)
94
-
95
- # ---------- FUNDING TAB ----------
96
- with gr.Tab("πŸ’° Funding & Investor Networks"):
97
- funding_input = gr.Textbox(label="Topic", placeholder="e.g., synthetic biology oncology startups")
98
- funding_btn = gr.Button("Generate Funding Map")
99
- funding_graph_out = gr.Image(label="Funding Network")
100
- funding_btn.click(run_funding_query, inputs=funding_input, outputs=funding_graph_out)
101
-
102
- # ---------- IMAGE ANALYSIS TAB ----------
103
- with gr.Tab("πŸ–ΌοΈ Microscopy / Image Analysis"):
104
- img_upload = gr.Image(type="filepath", label="Upload Image")
105
- img_btn = gr.Button("Analyze Image")
106
- img_analysis_out = gr.Textbox(label="Analysis Result")
107
- # Hook to your vision model here
108
- img_btn.click(lambda img: f"Analysis for {img}", inputs=img_upload, outputs=img_analysis_out)
109
-
110
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
  import os
3
  import gradio as gr
4
+ from genesis.pipeline import (
5
+ run_literature_mode,
6
+ run_molecule_mode,
7
+ run_pathway_mode,
8
+ run_funding_mode,
9
+ run_image_mode
10
+ )
11
+ from genesis.utils.pdf_export import export_pdf_report
12
+
13
+ # Load CSS
14
+ with open(os.path.join("genesis", "static", "style.css"), "r") as f:
15
+ custom_css = f.read()
16
+
17
+ HF_SPACE = os.environ.get("HF_SPACE", "false").lower() == "true"
18
+
19
+ # ---------------------------------------------------------
20
+ # Wrappers to ensure click-to-run functionality
21
+ # ---------------------------------------------------------
22
+
23
+ def literature_tab(query, narration, export_pdf):
24
+ result = run_literature_mode(query, narration=narration)
25
+ pdf_path = None
26
+ if export_pdf:
27
+ pdf_path = export_pdf_report(result)
28
+ return (
29
+ result.get("summary", ""),
30
+ result.get("citations", []),
31
+ result.get("visuals", None),
32
+ result.get("audio_url", None),
33
+ pdf_path
34
+ )
35
 
36
+ def molecule_tab(identifier, narration, export_pdf):
37
+ result = run_molecule_mode(identifier, narration=narration)
38
+ pdf_path = None
39
+ if export_pdf:
40
+ pdf_path = export_pdf_report(result)
41
  return (
42
+ result.get("summary", ""),
43
+ result.get("structure_3d", None),
44
+ result.get("properties", ""),
45
+ result.get("audio_url", None),
46
+ pdf_path
47
  )
48
 
49
+ def pathway_tab(pathway_name, narration, export_pdf):
50
+ result = run_pathway_mode(pathway_name, narration=narration)
51
+ pdf_path = None
52
+ if export_pdf:
53
+ pdf_path = export_pdf_report(result)
54
+ return (
55
+ result.get("summary", ""),
56
+ result.get("graph_svg", None),
57
+ result.get("analysis", ""),
58
+ result.get("audio_url", None),
59
+ pdf_path
60
+ )
61
 
62
+ def funding_tab(query, narration, export_pdf):
63
+ result = run_funding_mode(query, narration=narration)
64
+ pdf_path = None
65
+ if export_pdf:
66
+ pdf_path = export_pdf_report(result)
67
+ return (
68
+ result.get("summary", ""),
69
+ result.get("funding_graph", None),
70
+ result.get("top_investors", ""),
71
+ result.get("audio_url", None),
72
+ pdf_path
73
+ )
74
 
75
+ def image_tab(image, narration, export_pdf):
76
+ result = run_image_mode(image, narration=narration)
77
+ pdf_path = None
78
+ if export_pdf:
79
+ pdf_path = export_pdf_report(result)
80
+ return (
81
+ result.get("summary", ""),
82
+ result.get("annotations", None),
83
+ result.get("enhanced_image", None),
84
+ result.get("audio_url", None),
85
+ pdf_path
86
+ )
87
 
88
+ # ---------------------------------------------------------
89
+ # Build Gradio Interface
90
+ # ---------------------------------------------------------
91
+ with gr.Blocks(css=custom_css, theme=gr.themes.Monochrome()) as demo:
92
+ gr.Markdown("# 🧬 GENESIS-AI β€” The Synthetic Biology OS")
93
+ gr.Markdown("Multi-modal AI for Literature, Molecules, Pathways, Funding, and Images.")
94
 
95
+ with gr.Tab("πŸ“š Literature Review"):
96
+ with gr.Row():
97
+ query = gr.Textbox(label="Research Query")
98
  narration = gr.Checkbox(label="Enable Narration", value=False)
99
+ export_pdf = gr.Checkbox(label="Export PDF", value=False)
100
+ run_btn = gr.Button("Run Literature Review πŸš€")
101
+ summary = gr.Textbox(label="Summary", lines=10)
102
+ citations = gr.JSON(label="Citations")
103
+ visuals = gr.Image(label="Visuals")
104
+ audio_url = gr.Audio(label="Narration Audio")
105
+ pdf_out = gr.File(label="Download PDF")
106
+ run_btn.click(
107
+ literature_tab,
108
+ inputs=[query, narration, export_pdf],
109
+ outputs=[summary, citations, visuals, audio_url, pdf_out]
110
+ )
111
+
112
+ with gr.Tab("πŸ§ͺ Molecule Explorer"):
113
+ identifier = gr.Textbox(label="Molecule Name / Gene ID")
114
+ narration2 = gr.Checkbox(label="Enable Narration", value=False)
115
+ export_pdf2 = gr.Checkbox(label="Export PDF", value=False)
116
+ run_btn2 = gr.Button("Run Molecule Analysis πŸ”")
117
+ summary2 = gr.Textbox(label="Summary", lines=10)
118
+ structure_3d = gr.HTML(label="3D Structure Viewer")
119
+ properties = gr.Textbox(label="Properties")
120
+ audio_url2 = gr.Audio(label="Narration Audio")
121
+ pdf_out2 = gr.File(label="Download PDF")
122
+ run_btn2.click(
123
+ molecule_tab,
124
+ inputs=[identifier, narration2, export_pdf2],
125
+ outputs=[summary2, structure_3d, properties, audio_url2, pdf_out2]
126
+ )
127
+
128
+ with gr.Tab("🧬 Pathway Mapper"):
129
+ pathway_name = gr.Textbox(label="Pathway Name")
130
+ narration3 = gr.Checkbox(label="Enable Narration", value=False)
131
+ export_pdf3 = gr.Checkbox(label="Export PDF", value=False)
132
+ run_btn3 = gr.Button("Run Pathway Mapping 🧩")
133
+ summary3 = gr.Textbox(label="Summary", lines=10)
134
+ graph_svg = gr.HTML(label="Pathway Graph")
135
+ analysis = gr.Textbox(label="Analysis")
136
+ audio_url3 = gr.Audio(label="Narration Audio")
137
+ pdf_out3 = gr.File(label="Download PDF")
138
+ run_btn3.click(
139
+ pathway_tab,
140
+ inputs=[pathway_name, narration3, export_pdf3],
141
+ outputs=[summary3, graph_svg, analysis, audio_url3, pdf_out3]
142
+ )
143
+
144
+ with gr.Tab("πŸ’° Funding Network"):
145
+ funding_query = gr.Textbox(label="Funding Query (global)")
146
+ narration4 = gr.Checkbox(label="Enable Narration", value=False)
147
+ export_pdf4 = gr.Checkbox(label="Export PDF", value=False)
148
+ run_btn4 = gr.Button("Run Funding Analysis 🌍")
149
+ summary4 = gr.Textbox(label="Summary", lines=10)
150
+ funding_graph = gr.HTML(label="Funding Network Graph")
151
+ top_investors = gr.Textbox(label="Top Investors")
152
+ audio_url4 = gr.Audio(label="Narration Audio")
153
+ pdf_out4 = gr.File(label="Download PDF")
154
+ run_btn4.click(
155
+ funding_tab,
156
+ inputs=[funding_query, narration4, export_pdf4],
157
+ outputs=[summary4, funding_graph, top_investors, audio_url4, pdf_out4]
158
+ )
159
+
160
+ with gr.Tab("πŸ–ΌοΈ Image Analysis"):
161
+ img_input = gr.Image(type="filepath", label="Upload Microscopy or Diagram")
162
+ narration5 = gr.Checkbox(label="Enable Narration", value=False)
163
+ export_pdf5 = gr.Checkbox(label="Export PDF", value=False)
164
+ run_btn5 = gr.Button("Run Image Analysis πŸ–ΌοΈ")
165
+ summary5 = gr.Textbox(label="Summary", lines=10)
166
+ annotations = gr.Image(label="Annotated Image")
167
+ enhanced_image = gr.Image(label="Enhanced Image")
168
+ audio_url5 = gr.Audio(label="Narration Audio")
169
+ pdf_out5 = gr.File(label="Download PDF")
170
+ run_btn5.click(
171
+ image_tab,
172
+ inputs=[img_input, narration5, export_pdf5],
173
+ outputs=[summary5, annotations, enhanced_image, audio_url5, pdf_out5]
174
+ )
175
+
176
+ # ---------------------------------------------------------
177
+ # Launch
178
+ # ---------------------------------------------------------
179
+ if __name__ == "__main__":
180
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=HF_SPACE)