Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -13,11 +14,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import DuckDuckSearchTool , CodeAgent , HfApiModel
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
+
self.model = HfApiModel(
|
| 18 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 19 |
+
token=os.getenv("HF_TOKEN")
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
self.search_tool = DuckDuckSearchTool()
|
| 23 |
+
self.agent = CodeAgent(
|
| 24 |
+
tools=[self.search_tool],
|
| 25 |
+
model=self.model,
|
| 26 |
+
max_steps=15 # Increased for video processing
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
+
try:
|
| 31 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 32 |
+
fixed_answer = self.agent.run(question)
|
| 33 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 34 |
+
return fixed_answer
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error processing question: {str(e)}"
|
| 37 |
|
| 38 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 39 |
"""
|