Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,67 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import os, asyncio, json
|
4 |
import gradio as gr
|
5 |
from dotenv import load_dotenv
|
6 |
|
7 |
load_dotenv()
|
8 |
|
9 |
from genesis.pipeline import research_once
|
|
|
|
|
10 |
|
11 |
APP_TITLE = "GENESIS-AI β Synthetic Biology Deep Research (Safety-First)"
|
12 |
-
APP_DESC =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
return final_text, cites_md, json.dumps(out, indent=2)
|
20 |
|
21 |
with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
|
22 |
gr.Markdown(f"# {APP_TITLE}")
|
23 |
gr.Markdown(APP_DESC)
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
go = gr.Button("Run Deep Research", variant="primary")
|
28 |
|
29 |
with gr.Tabs():
|
@@ -33,8 +71,14 @@ with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
|
|
33 |
citations = gr.Markdown()
|
34 |
with gr.Tab("JSON Export"):
|
35 |
json_out = gr.Code(language="json")
|
|
|
|
|
36 |
|
37 |
-
go.click(
|
|
|
|
|
|
|
|
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
-
demo.launch()
|
|
|
1 |
+
rom __future__ import annotations
|
2 |
+
import os, json, asyncio, io
|
|
|
3 |
import gradio as gr
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
load_dotenv()
|
7 |
|
8 |
from genesis.pipeline import research_once
|
9 |
+
from genesis.providers import postprocess_summary
|
10 |
+
from genesis.graph import build_preview_graph_html
|
11 |
|
12 |
APP_TITLE = "GENESIS-AI β Synthetic Biology Deep Research (Safety-First)"
|
13 |
+
APP_DESC = (
|
14 |
+
"High-level synthetic biology literature synthesis with citations. "
|
15 |
+
"This app **never** produces operational protocols."
|
16 |
+
)
|
17 |
+
|
18 |
+
DEFAULT_POST = os.getenv("POSTPROCESSOR_DEFAULT", "none").lower()
|
19 |
+
DEFAULT_RERANK_MODEL = os.getenv("RERANK_MODEL", "mixedbread-ai/mxbai-rerank-large-v1")
|
20 |
+
|
21 |
+
async def run_pipeline(query: str, fast: bool, postprocessor: str, want_graph: bool) -> tuple:
|
22 |
+
out = await research_once(query, fast=fast, rerank_model=DEFAULT_RERANK_MODEL)
|
23 |
+
|
24 |
+
# Optional post-processing (Gemini/DeepSeek) for polish ONLY (no lab steps)
|
25 |
+
if postprocessor and postprocessor != "none":
|
26 |
+
out["final_output"] = await postprocess_summary(
|
27 |
+
base_text=out.get("final_output") or "",
|
28 |
+
citations=out.get("citations", []),
|
29 |
+
engine=postprocessor,
|
30 |
+
)
|
31 |
+
|
32 |
+
# Optional graph preview
|
33 |
+
graph_html = None
|
34 |
+
if want_graph:
|
35 |
+
graph_html = build_preview_graph_html(out.get("citations", []))
|
36 |
|
37 |
+
final_md = out.get("final_output") or "_No output_"
|
38 |
+
cites_md = "
|
39 |
+
".join([f"- [{c.get('title','link')}]({c.get('url','')})" for c in out.get("citations", [])]) or "_None detected_"
|
40 |
+
json_blob = json.dumps(out, indent=2)
|
41 |
+
return final_md, cites_md, json_blob, graph_html
|
|
|
42 |
|
43 |
with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
|
44 |
gr.Markdown(f"# {APP_TITLE}")
|
45 |
gr.Markdown(APP_DESC)
|
46 |
|
47 |
+
with gr.Row():
|
48 |
+
query = gr.Textbox(
|
49 |
+
label="Your high-level research request",
|
50 |
+
lines=5,
|
51 |
+
placeholder=(
|
52 |
+
"e.g., High-level synthesis of CRISPR base-editing trends in oncology (last 2 years). "
|
53 |
+
"Summarize mechanisms, targets, ethics, and provide citations."
|
54 |
+
),
|
55 |
+
)
|
56 |
+
with gr.Row():
|
57 |
+
fast = gr.Checkbox(label="Fast mode (o4-mini-deep-research)", value=False)
|
58 |
+
post = gr.Dropdown(
|
59 |
+
label="Post-processor",
|
60 |
+
choices=["none", "gemini", "deepseek"],
|
61 |
+
value=DEFAULT_POST,
|
62 |
+
allow_custom_value=False,
|
63 |
+
)
|
64 |
+
want_graph = gr.Checkbox(label="Build graph preview", value=False)
|
65 |
go = gr.Button("Run Deep Research", variant="primary")
|
66 |
|
67 |
with gr.Tabs():
|
|
|
71 |
citations = gr.Markdown()
|
72 |
with gr.Tab("JSON Export"):
|
73 |
json_out = gr.Code(language="json")
|
74 |
+
with gr.Tab("Graph Preview"):
|
75 |
+
graph_html = gr.HTML()
|
76 |
|
77 |
+
go.click(
|
78 |
+
fn=run_pipeline,
|
79 |
+
inputs=[query, fast, post, want_graph],
|
80 |
+
outputs=[report, citations, json_out, graph_html],
|
81 |
+
)
|
82 |
|
83 |
if __name__ == "__main__":
|
84 |
+
demo.launch()
|