Spaces:
Sleeping
Sleeping
File size: 3,030 Bytes
e3c954b 335600f e3c954b 335600f e3c954b 335600f e3c954b 335600f e3c954b 335600f e3c954b 335600f e3c954b 335600f e3c954b |
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 |
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() |