Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from dotenv import load_dotenv | |
| from research_manager import ResearchManager | |
| load_dotenv(override=True) | |
| async def run(query: str, recipient_email: str): | |
| """Show a short placeholder in Gradio; full step-by-step log stays in the terminal (prints).""" | |
| yield "*Running research…*" | |
| last = "" | |
| async for chunk in ResearchManager().run(query, recipient_email=recipient_email or None): | |
| last = str(chunk) | |
| yield last | |
| with gr.Blocks(theme=gr.themes.Default(primary_hue="sky")) as demo: | |
| gr.Markdown("# Deep Research") | |
| query_textbox = gr.Textbox(label="What topic would you like to research?") | |
| email_textbox = gr.Textbox( | |
| label="Email for report (optional)", | |
| placeholder="you@example.com", | |
| ) | |
| run_button = gr.Button("Run", variant="primary") | |
| report = gr.Markdown(label="Report") | |
| run_inputs = [query_textbox, email_textbox] | |
| run_button.click(fn=run, inputs=run_inputs, outputs=report) | |
| query_textbox.submit(fn=run, inputs=run_inputs, outputs=report) | |
| def launch_demo() -> None: | |
| """Local: open browser. Hugging Face / most hosts: PORT is set — bind 0.0.0.0 (never inbrowser there).""" | |
| port = os.environ.get("PORT") | |
| print(f"launch_demo: PORT={port!r}", flush=True) | |
| if port is not None: | |
| demo.launch(server_name="0.0.0.0", server_port=int(port)) | |
| else: | |
| demo.launch(inbrowser=True) | |
| if __name__ == "__main__": | |
| launch_demo() | |