Upload folder using huggingface_hub
Browse files- deep_research.py +17 -0
- requirements.txt +2 -1
deep_research.py
CHANGED
|
@@ -4,6 +4,16 @@ from research_manager import ResearchManager, ResearchManagerAgent
|
|
| 4 |
from agents import Runner, trace, gen_trace_id
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
load_dotenv(override=True)
|
| 8 |
|
| 9 |
# Available models for user selection
|
|
@@ -17,6 +27,7 @@ AVAILABLE_MODELS = [
|
|
| 17 |
"o1-mini"
|
| 18 |
]
|
| 19 |
|
|
|
|
| 20 |
async def handle_query_submission(query: str, current_state: dict, api_key: str, model: str):
|
| 21 |
"""Handle initial query submission - generate clarifying questions with progress"""
|
| 22 |
if not query.strip():
|
|
@@ -50,6 +61,7 @@ async def handle_query_submission(query: str, current_state: dict, api_key: str,
|
|
| 50 |
except Exception as e:
|
| 51 |
return f"β Error generating clarifying questions: {str(e)}", gr.update(visible=False), gr.update(visible=False), current_state
|
| 52 |
|
|
|
|
| 53 |
async def handle_research_with_answers(answers: str, current_state: dict, email_address: str, send_email: bool):
|
| 54 |
"""Handle research execution with clarification answers with progress updates"""
|
| 55 |
if not current_state.get("query"):
|
|
@@ -139,6 +151,7 @@ Please use these clarifications to focus and refine the research approach."""
|
|
| 139 |
except Exception as e:
|
| 140 |
return f"β Error during research: {str(e)}", current_state
|
| 141 |
|
|
|
|
| 142 |
async def run_direct_research(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
|
| 143 |
"""Run research directly without clarification using the new agent-based system"""
|
| 144 |
if not query.strip():
|
|
@@ -198,6 +211,7 @@ async def run_direct_research(query: str, api_key: str, model: str, email_addres
|
|
| 198 |
print(f"Error details: {error_details}")
|
| 199 |
return f"β Error during research: {str(e)}\n\nPlease check your API key and model selection, or try the Legacy Quick Research option if this persists."
|
| 200 |
|
|
|
|
| 201 |
async def run_legacy_research(query: str, api_key: str, model: str, email_address: str, send_email: bool):
|
| 202 |
"""Run research using the original ResearchManager class with email options"""
|
| 203 |
if not query.strip():
|
|
@@ -253,6 +267,7 @@ async def run_legacy_research(query: str, api_key: str, model: str, email_addres
|
|
| 253 |
print(f"Error details: {error_details}")
|
| 254 |
return f"β Error during research: {str(e)}\n\nPlease check your API key and model selection."
|
| 255 |
|
|
|
|
| 256 |
async def run_direct_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
|
| 257 |
"""Run direct research with real-time progress tracking"""
|
| 258 |
if not query.strip():
|
|
@@ -283,6 +298,7 @@ async def run_direct_research_with_progress(query: str, api_key: str, model: str
|
|
| 283 |
print(f"Error details: {error_details}")
|
| 284 |
yield f"β Error during research: {str(e)}\n\nPlease check your API key and model selection."
|
| 285 |
|
|
|
|
| 286 |
async def run_enhanced_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
|
| 287 |
"""Run enhanced research with real-time progress tracking"""
|
| 288 |
if not query.strip():
|
|
@@ -313,6 +329,7 @@ async def run_enhanced_research_with_progress(query: str, api_key: str, model: s
|
|
| 313 |
print(f"Error details: {error_details}")
|
| 314 |
yield f"β Error during enhanced research: {str(e)}\n\nPlease check your API key and model selection."
|
| 315 |
|
|
|
|
| 316 |
async def run_clarified_research_with_progress(answers: str, current_state: dict, email_address: str, send_email: bool):
|
| 317 |
"""Run research with clarification answers and real-time progress tracking"""
|
| 318 |
if not current_state.get("query"):
|
|
|
|
| 4 |
from agents import Runner, trace, gen_trace_id
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Import spaces for ZeroGPU compatibility
|
| 8 |
+
try:
|
| 9 |
+
import spaces
|
| 10 |
+
except ImportError:
|
| 11 |
+
# Fallback for local development
|
| 12 |
+
class spaces:
|
| 13 |
+
@staticmethod
|
| 14 |
+
def GPU(func):
|
| 15 |
+
return func
|
| 16 |
+
|
| 17 |
load_dotenv(override=True)
|
| 18 |
|
| 19 |
# Available models for user selection
|
|
|
|
| 27 |
"o1-mini"
|
| 28 |
]
|
| 29 |
|
| 30 |
+
@spaces.GPU
|
| 31 |
async def handle_query_submission(query: str, current_state: dict, api_key: str, model: str):
|
| 32 |
"""Handle initial query submission - generate clarifying questions with progress"""
|
| 33 |
if not query.strip():
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
return f"β Error generating clarifying questions: {str(e)}", gr.update(visible=False), gr.update(visible=False), current_state
|
| 63 |
|
| 64 |
+
@spaces.GPU
|
| 65 |
async def handle_research_with_answers(answers: str, current_state: dict, email_address: str, send_email: bool):
|
| 66 |
"""Handle research execution with clarification answers with progress updates"""
|
| 67 |
if not current_state.get("query"):
|
|
|
|
| 151 |
except Exception as e:
|
| 152 |
return f"β Error during research: {str(e)}", current_state
|
| 153 |
|
| 154 |
+
@spaces.GPU
|
| 155 |
async def run_direct_research(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
|
| 156 |
"""Run research directly without clarification using the new agent-based system"""
|
| 157 |
if not query.strip():
|
|
|
|
| 211 |
print(f"Error details: {error_details}")
|
| 212 |
return f"β Error during research: {str(e)}\n\nPlease check your API key and model selection, or try the Legacy Quick Research option if this persists."
|
| 213 |
|
| 214 |
+
@spaces.GPU
|
| 215 |
async def run_legacy_research(query: str, api_key: str, model: str, email_address: str, send_email: bool):
|
| 216 |
"""Run research using the original ResearchManager class with email options"""
|
| 217 |
if not query.strip():
|
|
|
|
| 267 |
print(f"Error details: {error_details}")
|
| 268 |
return f"β Error during research: {str(e)}\n\nPlease check your API key and model selection."
|
| 269 |
|
| 270 |
+
@spaces.GPU
|
| 271 |
async def run_direct_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
|
| 272 |
"""Run direct research with real-time progress tracking"""
|
| 273 |
if not query.strip():
|
|
|
|
| 298 |
print(f"Error details: {error_details}")
|
| 299 |
yield f"β Error during research: {str(e)}\n\nPlease check your API key and model selection."
|
| 300 |
|
| 301 |
+
@spaces.GPU
|
| 302 |
async def run_enhanced_research_with_progress(query: str, api_key: str, model: str, email_address: str = "", send_email: bool = False):
|
| 303 |
"""Run enhanced research with real-time progress tracking"""
|
| 304 |
if not query.strip():
|
|
|
|
| 329 |
print(f"Error details: {error_details}")
|
| 330 |
yield f"β Error during enhanced research: {str(e)}\n\nPlease check your API key and model selection."
|
| 331 |
|
| 332 |
+
@spaces.GPU
|
| 333 |
async def run_clarified_research_with_progress(answers: str, current_state: dict, email_address: str, send_email: bool):
|
| 334 |
"""Run research with clarification answers and real-time progress tracking"""
|
| 335 |
if not current_state.get("query"):
|
requirements.txt
CHANGED
|
@@ -7,4 +7,5 @@ requests>=2.32.3
|
|
| 7 |
bs4>=0.0.2
|
| 8 |
httpx>=0.28.1
|
| 9 |
pydantic>=2.0.0
|
| 10 |
-
typing-extensions>=4.0.0
|
|
|
|
|
|
| 7 |
bs4>=0.0.2
|
| 8 |
httpx>=0.28.1
|
| 9 |
pydantic>=2.0.0
|
| 10 |
+
typing-extensions>=4.0.0
|
| 11 |
+
spaces>=0.28.3
|