Spaces:
Sleeping
Sleeping
rom __future__ import annotations | |
import os, json, asyncio, io | |
import gradio as gr | |
from dotenv import load_dotenv | |
load_dotenv() | |
from genesis.pipeline import research_once | |
from genesis.providers import postprocess_summary | |
from genesis.graph import build_preview_graph_html | |
APP_TITLE = "GENESIS-AI β Synthetic Biology Deep Research (Safety-First)" | |
APP_DESC = ( | |
"High-level synthetic biology literature synthesis with citations. " | |
"This app **never** produces operational protocols." | |
) | |
DEFAULT_POST = os.getenv("POSTPROCESSOR_DEFAULT", "none").lower() | |
DEFAULT_RERANK_MODEL = os.getenv("RERANK_MODEL", "mixedbread-ai/mxbai-rerank-large-v1") | |
async def run_pipeline(query: str, fast: bool, postprocessor: str, want_graph: bool) -> tuple: | |
out = await research_once(query, fast=fast, rerank_model=DEFAULT_RERANK_MODEL) | |
# Optional post-processing (Gemini/DeepSeek) for polish ONLY (no lab steps) | |
if postprocessor and postprocessor != "none": | |
out["final_output"] = await postprocess_summary( | |
base_text=out.get("final_output") or "", | |
citations=out.get("citations", []), | |
engine=postprocessor, | |
) | |
# Optional graph preview | |
graph_html = None | |
if want_graph: | |
graph_html = build_preview_graph_html(out.get("citations", [])) | |
final_md = out.get("final_output") or "_No output_" | |
cites_md = " | |
".join([f"- [{c.get('title','link')}]({c.get('url','')})" for c in out.get("citations", [])]) or "_None detected_" | |
json_blob = json.dumps(out, indent=2) | |
return final_md, cites_md, json_blob, graph_html | |
with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo: | |
gr.Markdown(f"# {APP_TITLE}") | |
gr.Markdown(APP_DESC) | |
with gr.Row(): | |
query = gr.Textbox( | |
label="Your high-level research request", | |
lines=5, | |
placeholder=( | |
"e.g., High-level synthesis of CRISPR base-editing trends in oncology (last 2 years). " | |
"Summarize mechanisms, targets, ethics, and provide citations." | |
), | |
) | |
with gr.Row(): | |
fast = gr.Checkbox(label="Fast mode (o4-mini-deep-research)", value=False) | |
post = gr.Dropdown( | |
label="Post-processor", | |
choices=["none", "gemini", "deepseek"], | |
value=DEFAULT_POST, | |
allow_custom_value=False, | |
) | |
want_graph = gr.Checkbox(label="Build graph preview", value=False) | |
go = gr.Button("Run Deep Research", variant="primary") | |
with gr.Tabs(): | |
with gr.Tab("Research Report"): | |
report = gr.Markdown() | |
with gr.Tab("Citations"): | |
citations = gr.Markdown() | |
with gr.Tab("JSON Export"): | |
json_out = gr.Code(language="json") | |
with gr.Tab("Graph Preview"): | |
graph_html = gr.HTML() | |
go.click( | |
fn=run_pipeline, | |
inputs=[query, fast, post, want_graph], | |
outputs=[report, citations, json_out, graph_html], | |
) | |
if __name__ == "__main__": | |
demo.launch() |