File size: 6,977 Bytes
e589553
7984ae1
2f85a76
e589553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8cec585
e589553
 
 
 
 
2f85a76
e589553
 
 
 
 
2f85a76
8cec585
e589553
 
 
 
 
 
 
 
 
 
 
 
7984ae1
e589553
 
 
 
 
 
 
 
 
 
 
 
7984ae1
e589553
 
 
 
 
 
 
 
 
 
 
 
7984ae1
e589553
 
 
 
 
 
7984ae1
e589553
 
 
2f85a76
e589553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# app.py
import os
import gradio as gr
from genesis.pipeline import (
    run_literature_mode,
    run_molecule_mode,
    run_pathway_mode,
    run_funding_mode,
    run_image_mode
)
from genesis.utils.pdf_export import export_pdf_report

# Load CSS
with open(os.path.join("genesis", "static", "style.css"), "r") as f:
    custom_css = f.read()

HF_SPACE = os.environ.get("HF_SPACE", "false").lower() == "true"

# ---------------------------------------------------------
# Wrappers to ensure click-to-run functionality
# ---------------------------------------------------------

def literature_tab(query, narration, export_pdf):
    result = run_literature_mode(query, narration=narration)
    pdf_path = None
    if export_pdf:
        pdf_path = export_pdf_report(result)
    return (
        result.get("summary", ""),
        result.get("citations", []),
        result.get("visuals", None),
        result.get("audio_url", None),
        pdf_path
    )

def molecule_tab(identifier, narration, export_pdf):
    result = run_molecule_mode(identifier, narration=narration)
    pdf_path = None
    if export_pdf:
        pdf_path = export_pdf_report(result)
    return (
        result.get("summary", ""),
        result.get("structure_3d", None),
        result.get("properties", ""),
        result.get("audio_url", None),
        pdf_path
    )

def pathway_tab(pathway_name, narration, export_pdf):
    result = run_pathway_mode(pathway_name, narration=narration)
    pdf_path = None
    if export_pdf:
        pdf_path = export_pdf_report(result)
    return (
        result.get("summary", ""),
        result.get("graph_svg", None),
        result.get("analysis", ""),
        result.get("audio_url", None),
        pdf_path
    )

def funding_tab(query, narration, export_pdf):
    result = run_funding_mode(query, narration=narration)
    pdf_path = None
    if export_pdf:
        pdf_path = export_pdf_report(result)
    return (
        result.get("summary", ""),
        result.get("funding_graph", None),
        result.get("top_investors", ""),
        result.get("audio_url", None),
        pdf_path
    )

def image_tab(image, narration, export_pdf):
    result = run_image_mode(image, narration=narration)
    pdf_path = None
    if export_pdf:
        pdf_path = export_pdf_report(result)
    return (
        result.get("summary", ""),
        result.get("annotations", None),
        result.get("enhanced_image", None),
        result.get("audio_url", None),
        pdf_path
    )

# ---------------------------------------------------------
# Build Gradio Interface
# ---------------------------------------------------------
with gr.Blocks(css=custom_css, theme=gr.themes.Monochrome()) as demo:
    gr.Markdown("# 🧬 GENESIS-AI β€” The Synthetic Biology OS")
    gr.Markdown("Multi-modal AI for Literature, Molecules, Pathways, Funding, and Images.")

    with gr.Tab("πŸ“š Literature Review"):
        with gr.Row():
            query = gr.Textbox(label="Research Query")
            narration = gr.Checkbox(label="Enable Narration", value=False)
            export_pdf = gr.Checkbox(label="Export PDF", value=False)
        run_btn = gr.Button("Run Literature Review πŸš€")
        summary = gr.Textbox(label="Summary", lines=10)
        citations = gr.JSON(label="Citations")
        visuals = gr.Image(label="Visuals")
        audio_url = gr.Audio(label="Narration Audio")
        pdf_out = gr.File(label="Download PDF")
        run_btn.click(
            literature_tab,
            inputs=[query, narration, export_pdf],
            outputs=[summary, citations, visuals, audio_url, pdf_out]
        )

    with gr.Tab("πŸ§ͺ Molecule Explorer"):
        identifier = gr.Textbox(label="Molecule Name / Gene ID")
        narration2 = gr.Checkbox(label="Enable Narration", value=False)
        export_pdf2 = gr.Checkbox(label="Export PDF", value=False)
        run_btn2 = gr.Button("Run Molecule Analysis πŸ”")
        summary2 = gr.Textbox(label="Summary", lines=10)
        structure_3d = gr.HTML(label="3D Structure Viewer")
        properties = gr.Textbox(label="Properties")
        audio_url2 = gr.Audio(label="Narration Audio")
        pdf_out2 = gr.File(label="Download PDF")
        run_btn2.click(
            molecule_tab,
            inputs=[identifier, narration2, export_pdf2],
            outputs=[summary2, structure_3d, properties, audio_url2, pdf_out2]
        )

    with gr.Tab("🧬 Pathway Mapper"):
        pathway_name = gr.Textbox(label="Pathway Name")
        narration3 = gr.Checkbox(label="Enable Narration", value=False)
        export_pdf3 = gr.Checkbox(label="Export PDF", value=False)
        run_btn3 = gr.Button("Run Pathway Mapping 🧩")
        summary3 = gr.Textbox(label="Summary", lines=10)
        graph_svg = gr.HTML(label="Pathway Graph")
        analysis = gr.Textbox(label="Analysis")
        audio_url3 = gr.Audio(label="Narration Audio")
        pdf_out3 = gr.File(label="Download PDF")
        run_btn3.click(
            pathway_tab,
            inputs=[pathway_name, narration3, export_pdf3],
            outputs=[summary3, graph_svg, analysis, audio_url3, pdf_out3]
        )

    with gr.Tab("πŸ’° Funding Network"):
        funding_query = gr.Textbox(label="Funding Query (global)")
        narration4 = gr.Checkbox(label="Enable Narration", value=False)
        export_pdf4 = gr.Checkbox(label="Export PDF", value=False)
        run_btn4 = gr.Button("Run Funding Analysis 🌍")
        summary4 = gr.Textbox(label="Summary", lines=10)
        funding_graph = gr.HTML(label="Funding Network Graph")
        top_investors = gr.Textbox(label="Top Investors")
        audio_url4 = gr.Audio(label="Narration Audio")
        pdf_out4 = gr.File(label="Download PDF")
        run_btn4.click(
            funding_tab,
            inputs=[funding_query, narration4, export_pdf4],
            outputs=[summary4, funding_graph, top_investors, audio_url4, pdf_out4]
        )

    with gr.Tab("πŸ–ΌοΈ Image Analysis"):
        img_input = gr.Image(type="filepath", label="Upload Microscopy or Diagram")
        narration5 = gr.Checkbox(label="Enable Narration", value=False)
        export_pdf5 = gr.Checkbox(label="Export PDF", value=False)
        run_btn5 = gr.Button("Run Image Analysis πŸ–ΌοΈ")
        summary5 = gr.Textbox(label="Summary", lines=10)
        annotations = gr.Image(label="Annotated Image")
        enhanced_image = gr.Image(label="Enhanced Image")
        audio_url5 = gr.Audio(label="Narration Audio")
        pdf_out5 = gr.File(label="Download PDF")
        run_btn5.click(
            image_tab,
            inputs=[img_input, narration5, export_pdf5],
            outputs=[summary5, annotations, enhanced_image, audio_url5, pdf_out5]
        )

# ---------------------------------------------------------
# Launch
# ---------------------------------------------------------
if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860, share=HF_SPACE)