Spaces:
Sleeping
Sleeping
Download research_manager.py from rohan131/Deep_Research: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/spaces/rohan131/Deep_Research/resolve/main/research_manager.py
- Command line
-
hf download hf://spaces/rohan131/Deep_Research/research_manager.py
-
curl -L -o research_manager.py https://huggingface.co/spaces/rohan131/Deep_Research/resolve/main/research_manager.py
1.94 kB
| import asyncio | |
| import uuid | |
| from planner_agent import generate_search_plan | |
| from search_agent import perform_search | |
| from writer_agent import generate_report, ReportData | |
| from email_agent import send_email | |
| class ResearchManager: | |
| async def run(self, query: str): | |
| trace_id = str(uuid.uuid4()) | |
| yield f"Trace ID: {trace_id}" | |
| yield "Planning searches..." | |
| search_plan = generate_search_plan(query) | |
| yield "Performing searches..." | |
| search_results = await self.perform_searches(search_plan) | |
| yield "Writing report..." | |
| report = generate_report(query, search_results) | |
| yield "Sending email..." | |
| html_body = self.build_html_report(report) | |
| send_email("Research Report", html_body) | |
| yield "✅ Research complete!" | |
| yield report.markdown_report | |
| async def perform_searches(self, search_plan) -> list[str]: | |
| tasks = [asyncio.create_task(perform_search(item)) for item in search_plan.searches] | |
| results = [] | |
| for task in asyncio.as_completed(tasks): | |
| results.append(await task) | |
| return results | |
| def build_html_report(self, report: ReportData) -> str: | |
| key_points_html = "".join(f"<li>{p}</li>" for p in report.key_points) | |
| citations_html = "".join(f"<li><a href='{url}'>{url}</a></li>" for url in report.citations) | |
| questions_html = "".join(f"<li>{q}</li>" for q in report.follow_up_questions) | |
| return f""" | |
| <html> | |
| <body> | |
| <h2>Research Summary</h2> | |
| <p>{report.short_summary}</p> | |
| <h3>Key Points</h3> | |
| <ul>{key_points_html}</ul> | |
| <h3>Citations</h3> | |
| <ul>{citations_html}</ul> | |
| <h3>Follow-Up Questions</h3> | |
| <ul>{questions_html}</ul> | |
| </body> | |
| </html> | |
| """ | |