Spaces:
Sleeping

File size: 1,675 Bytes
f233663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from dotenv import load_dotenv
from research2_manager import ResearchManager  # make sure this is your latest version

load_dotenv(override=True)


# --- Async generator that streams the manager output ---
async def run(query: str, clarifications: str):
    """Stream the ResearchManager output into the Gradio interface."""
    try:
        async for chunk in ResearchManager().run(query=query, clarifications=clarifications or None):
            yield chunk
    except Exception as e:
        yield f"**Error:** {e!s}"


# --- Gradio UI ---
with gr.Blocks(theme=gr.themes.Default(primary_hue="sky")) as ui:
    gr.Markdown("## 🔎 Deep Research Agent (Interactive — No Email)")

    with gr.Row():
        query_textbox = gr.Textbox(
            label="Main Research Query",
            placeholder="e.g. Battery storage logistics in Southeast Asia",
            lines=2,
        )
        clarification_box = gr.Textbox(
            label="Answers to Clarifying Questions",
            placeholder="(Leave blank on first run — you’ll get questions back.)",
            lines=4,
        )

    run_button = gr.Button("▶️ Run Research", variant="primary")
    report_output = gr.Markdown("")

    # Hook up the run function (async streaming)
    run_button.click(
        fn=run,
        inputs=[query_textbox, clarification_box],
        outputs=report_output,
    )
    query_textbox.submit(
        fn=run,
        inputs=[query_textbox, clarification_box],
        outputs=report_output,
    )

# --- Enable async queue ---
if __name__ == "__main__":
    ui.queue(default_concurrency_limit=2, status_update_rate=1).launch(inbrowser=True)