mgbam commited on
Commit
3acac05
Β·
verified Β·
1 Parent(s): f9cc55d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +130 -174
app.py CHANGED
@@ -1,180 +1,136 @@
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)
 
1
  # app.py
 
2
  import gradio as gr
3
+ from genesis.providers import (
4
+ run_pubmed_literature,
5
+ run_chembl_search,
6
+ run_bioportal_ontology,
7
+ run_ncbi_gene_lookup,
8
+ ai_generate_text,
9
+ ai_generate_image,
10
+ run_tts,
11
+ query_funding_network,
12
+ query_pathway_graph
13
  )
14
+ from genesis.utils.pdf_export import export_pdf
15
+ import tempfile, os
16
+
17
+ # ========================
18
+ # HELPER FUNCTIONS
19
+ # ========================
20
+ def search_literature(query):
21
+ results = run_pubmed_literature(query, max_results=5)
22
+ if not results:
23
+ return "No results found."
24
+ return results
25
+
26
+ def molecule_lookup(molecule):
27
+ return run_chembl_search(molecule)
28
+
29
+ def ontology_lookup(term):
30
+ return run_bioportal_ontology(term)
31
+
32
+ def gene_lookup(gene_id):
33
+ return run_ncbi_gene_lookup(gene_id)
34
+
35
+ def funding_map(keyword):
36
+ data = query_funding_network(keyword)
37
+ return data if data else "No funding connections found."
38
+
39
+ def pathway_map(pathway):
40
+ data = query_pathway_graph(pathway)
41
+ return data if data else "No pathway data found."
42
+
43
+ def generate_ai_summary(prompt, model_choice):
44
+ return ai_generate_text(prompt, model=model_choice)
45
+
46
+ def generate_ai_image(prompt):
47
+ return ai_generate_image(prompt)
48
+
49
+ def narrate_summary(text, voice):
50
+ audio = run_tts(text, voice=voice)
51
+ if audio:
52
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
53
+ with open(temp_file.name, "wb") as f:
54
+ f.write(audio)
55
+ return temp_file.name
56
+ return None
57
+
58
+ def export_results_to_pdf(content):
59
+ pdf_path = export_pdf(content)
60
+ return pdf_path
61
+
62
+ # ========================
63
+ # UI DESIGN
64
+ # ========================
65
+ with gr.Blocks(css="static/style.css", theme=gr.themes.Soft()) as demo:
66
+ gr.HTML("<h1>🧬 GENESIS-AI β€” Synthetic Biology Research OS</h1>")
67
+ gr.HTML("<p>Multi-modal intelligence for scientists. Powered by AI + global biology databases.</p>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  with gr.Tab("πŸ“š Literature Review"):
70
+ lit_query = gr.Textbox(label="Enter Search Query")
71
+ lit_btn = gr.Button("Search Literature")
72
+ lit_output = gr.JSON(label="Results")
73
+ lit_btn.click(search_literature, inputs=lit_query, outputs=lit_output)
74
+
75
+ with gr.Tab("πŸ§ͺ Molecule & Gene Lookup"):
76
+ mol_input = gr.Textbox(label="Molecule Name")
77
+ mol_btn = gr.Button("Search Molecule")
78
+ mol_output = gr.JSON()
79
+
80
+ gene_input = gr.Textbox(label="Gene ID")
81
+ gene_btn = gr.Button("Lookup Gene")
82
+ gene_output = gr.JSON()
83
+
84
+ mol_btn.click(molecule_lookup, inputs=mol_input, outputs=mol_output)
85
+ gene_btn.click(gene_lookup, inputs=gene_input, outputs=gene_output)
86
+
87
+ with gr.Tab("πŸ”¬ Ontology & Pathway Mapping"):
88
+ term_input = gr.Textbox(label="Ontology Term")
89
+ term_btn = gr.Button("Search Ontology")
90
+ term_output = gr.JSON()
91
+
92
+ pathway_input = gr.Textbox(label="Pathway Name")
93
+ pathway_btn = gr.Button("Map Pathway")
94
+ pathway_output = gr.JSON()
95
+
96
+ term_btn.click(ontology_lookup, inputs=term_input, outputs=term_output)
97
+ pathway_btn.click(pathway_map, inputs=pathway_input, outputs=pathway_output)
98
+
99
+ with gr.Tab("πŸ’° Funding Networks"):
100
+ fund_input = gr.Textbox(label="Keyword (Company / Topic)")
101
+ fund_btn = gr.Button("Find Funding Connections")
102
+ fund_output = gr.JSON()
103
+ fund_btn.click(funding_map, inputs=fund_input, outputs=fund_output)
104
+
105
+ with gr.Tab("🎨 AI Tools"):
106
+ # AI Text
107
+ ai_prompt = gr.Textbox(label="Prompt for AI")
108
+ ai_model = gr.Dropdown(choices=["gemini", "openai", "claude", "deepseek"], value="gemini", label="Model")
109
+ ai_btn = gr.Button("Generate Summary")
110
+ ai_output = gr.Textbox(label="AI Summary")
111
+ ai_btn.click(generate_ai_summary, inputs=[ai_prompt, ai_model], outputs=ai_output)
112
+
113
+ # AI Image
114
+ img_prompt = gr.Textbox(label="Prompt for Image")
115
+ img_btn = gr.Button("Generate Image")
116
+ img_output = gr.Image()
117
+ img_btn.click(generate_ai_image, inputs=img_prompt, outputs=img_output)
118
+
119
+ # Narration
120
+ narr_text = gr.Textbox(label="Text to Narrate")
121
+ narr_voice = gr.Dropdown(choices=["Rachel", "Bella", "Antoni"], value="Rachel", label="Voice")
122
+ narr_btn = gr.Button("Narrate")
123
+ narr_output = gr.Audio()
124
+ narr_btn.click(narrate_summary, inputs=[narr_text, narr_voice], outputs=narr_output)
125
+
126
+ with gr.Row():
127
+ pdf_text = gr.Textbox(label="Enter text/content for PDF export")
128
+ pdf_btn = gr.Button("Export PDF")
129
+ pdf_file = gr.File(label="Download PDF")
130
+ pdf_btn.click(export_results_to_pdf, inputs=pdf_text, outputs=pdf_file)
131
+
132
+ # ========================
133
+ # APP LAUNCH
134
+ # ========================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  if __name__ == "__main__":
136
+ demo.launch(server_name="0.0.0.0", server_port=7860)