Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,110 +1,180 @@
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from genesis.pipeline import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
return (
|
32 |
-
result
|
33 |
-
|
34 |
-
result
|
35 |
-
result
|
36 |
-
|
37 |
)
|
38 |
|
39 |
-
def
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
def
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
def
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
with gr.
|
59 |
-
|
60 |
-
|
61 |
narration = gr.Checkbox(label="Enable Narration", value=False)
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|