Spaces:
Runtime error
Runtime error
File size: 2,062 Bytes
b49011b | 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 | # --- Imports ---
import os
import random
import gradio as gr
from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel, WikipediaSearchTool
from tools import DownloadTaskAttachmentTool, VisitWebpageTool
class MyAgent:
def __init__(self):
self.evaluation_agent = CodeAgent(
model=LiteLLMModel(model_id="openrouter/qwen/qwen3-235b-a22b:free", api_key=os.getenv("OPENROUTER_KEY")),
tools=[DuckDuckGoSearchTool(), DownloadTaskAttachmentTool(), VisitWebpageTool(), WikipediaSearchTool()],
add_base_tools=True,
additional_authorized_imports=['pandas', 'numpy', 'csv', 'subprocess', 'exec']
)
print("Evaluation agent instance created.")
def __call__(self, query: str) -> str:
print(f"Processing query (initial segment): {query[:50]}...")
response = self.evaluation_agent.run(query)
print(f"Generated response: {response}")
return response
def download_file(self, task_id: str) -> str:
"""
Retrieves task-specific file from remote storage.
Returns local storage path for the downloaded file.
"""
download_url = f"{DEFAULT_API_URL}/files/{task_id}"
save_path = f"downloads/{task_id}.file"
print(f"Downloading file for task ID {task_id} from {download_url}...")
try:
response = requests.get(download_url, stream=True, timeout=15)
response.raise_for_status()
os.makedirs("downloads", exist_ok=True)
with open(save_path, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
print(f"File downloaded successfully: {save_path}")
return save_path
except requests.exceptions.RequestException as e:
print(f"Error downloading file for task {task_id}: {e}")
raise
def launch_ui(self):
GradioUI(self.agent).launch()
# if __name__ == "__main__":
# my_agent = MyAgent()
# my_agent.launch_ui()
|