Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,180 +1,136 @@
|
|
1 |
# app.py
|
2 |
-
import os
|
3 |
import gradio as gr
|
4 |
-
from genesis.
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
)
|
11 |
-
from genesis.utils.pdf_export import
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
def
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
def
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
return (
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
)
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
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 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
)
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
)
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
)
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
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
|
|
|
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)
|