mgbam's picture
Update app.py
2f85a76 verified
raw
history blame
4.68 kB
import os
import gradio as gr
from genesis.pipeline import research_once
from genesis.visualization import generate_pathway_graph, generate_funding_network
# Environment variables
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
ELEVEN_LABS_API_KEY = os.getenv("ELEVEN_LABS_API_KEY")
# Preloaded demo queries
DEMO_QUERIES = [
"CRISPR living therapeutics in clinical trials since 2020",
"AI-designed enzymes for plastic degradation β€” literature + pathways",
"Synthetic biology startups in oncology β€” funding map",
"Metabolic pathway for artemisinin biosynthesis in yeast",
"Oncolytic virus engineering β€” biosecurity risk analysis"
]
# Custom LCARS biotech theme
CUSTOM_CSS = """
body {background-color: #001f1f; color: #ccffcc;}
.gradio-container {font-family: 'Orbitron', sans-serif;}
button {background-color: #ff6600 !important; color: white !important;}
textarea, input {background-color: #003333; color: #ccffcc;}
.tab-nav {background-color: #004d4d !important;}
"""
# -------------------- UI Functions -------------------- #
def run_text_query(query, narration):
result = research_once(query, narration=narration)
return (
result["summary"],
format_citations(result["citations"]),
result["visual_image_url"],
result["structures"],
result["audio_url"] if narration else None
)
def run_pathway_query(pathway_name):
return generate_pathway_graph(pathway_name)
def run_funding_query(topic):
return generate_funding_network(topic)
def format_citations(citations):
if not citations:
return "No citations found."
md = ""
for cite in citations:
md += f"- [{cite['type']}]({cite['url']})\n"
return md
# -------------------- Build UI -------------------- #
with gr.Blocks(css=CUSTOM_CSS, theme="default") as demo:
gr.Markdown("# 🧬 GENESIS-AI β€” Synthetic Biology Command Center")
gr.Markdown("**Multi-modal AI platform linking molecules, pathways, funding, and regulations**")
with gr.Tabs():
# ---------- TEXT QUERY TAB ----------
with gr.Tab("πŸ“œ Literature & Regulatory Analysis"):
narration = gr.Checkbox(label="Enable Narration", value=False)
text_input = gr.Textbox(label="Enter your query", placeholder="Type your synthetic biology research question...")
run_btn = gr.Button("Run Research")
demo_btns = gr.Row()
for q in DEMO_QUERIES:
demo_btns.add(gr.Button(q))
summary_out = gr.Textbox(label="Summary")
cites_out = gr.Markdown()
img_out = gr.Image(label="Generated Diagram")
struct_out = gr.JSON(label="Molecular Structures")
audio_out = gr.Audio(label="Narration", type="filepath")
run_btn.click(
fn=run_text_query,
inputs=[text_input, narration],
outputs=[summary_out, cites_out, img_out, struct_out, audio_out]
)
for q in DEMO_QUERIES:
demo_btns.children[DEMO_QUERIES.index(q)].click(
fn=run_text_query,
inputs=[gr.Textbox(value=q, visible=False), narration],
outputs=[summary_out, cites_out, img_out, struct_out, audio_out]
)
# ---------- PATHWAY TAB ----------
with gr.Tab("πŸ§ͺ Metabolic Pathway Mapping"):
pathway_input = gr.Textbox(label="Pathway Name", placeholder="e.g., artemisinin biosynthesis")
pathway_btn = gr.Button("Generate Pathway Graph")
pathway_graph_out = gr.Image(label="Pathway Graph")
pathway_btn.click(run_pathway_query, inputs=pathway_input, outputs=pathway_graph_out)
# ---------- FUNDING TAB ----------
with gr.Tab("πŸ’° Funding & Investor Networks"):
funding_input = gr.Textbox(label="Topic", placeholder="e.g., synthetic biology oncology startups")
funding_btn = gr.Button("Generate Funding Map")
funding_graph_out = gr.Image(label="Funding Network")
funding_btn.click(run_funding_query, inputs=funding_input, outputs=funding_graph_out)
# ---------- IMAGE ANALYSIS TAB ----------
with gr.Tab("πŸ–ΌοΈ Microscopy / Image Analysis"):
img_upload = gr.Image(type="filepath", label="Upload Image")
img_btn = gr.Button("Analyze Image")
img_analysis_out = gr.Textbox(label="Analysis Result")
# Hook to your vision model here
img_btn.click(lambda img: f"Analysis for {img}", inputs=img_upload, outputs=img_analysis_out)
demo.launch(server_name="0.0.0.0", server_port=7860)