Spaces:
Sleeping
Sleeping
| # app.py | |
| import asyncio | |
| import gradio as gr | |
| from dotenv import load_dotenv | |
| from research_manager import ResearchManager | |
| load_dotenv(override=True) | |
| manager = ResearchManager() | |
| def run(query: str): | |
| """ | |
| Hugging Face Spaces requires sync functions. | |
| This safely consumes your async generator. | |
| """ | |
| loop = asyncio.new_event_loop() | |
| asyncio.set_event_loop(loop) | |
| outputs = [] | |
| async_gen = manager.run(query) | |
| try: | |
| while True: | |
| chunk = loop.run_until_complete(async_gen.__anext__()) | |
| outputs.append(chunk) | |
| except StopAsyncIteration: | |
| pass | |
| finally: | |
| loop.close() | |
| # Return the final combined output | |
| return "\n\n".join(outputs) | |
| with gr.Blocks(theme=gr.themes.Default(primary_hue="sky")) as ui: | |
| gr.Markdown("# 🔍 Deep Research Agent") | |
| query_textbox = gr.Textbox( | |
| label="What topic would you like to research?", | |
| placeholder="e.g. Latest AI agent frameworks in 2025", | |
| ) | |
| run_button = gr.Button("Run", variant="primary") | |
| report = gr.Markdown(label="Output") | |
| run_button.click( | |
| fn=run, | |
| inputs=query_textbox, | |
| outputs=report, | |
| ) | |
| query_textbox.submit( | |
| fn=run, | |
| inputs=query_textbox, | |
| outputs=report, | |
| ) | |
| ui.launch() | |