Update app.py
#76
by
erdikent
- opened
app.py
CHANGED
@@ -10,14 +10,51 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
10 |
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
print("BasicAgent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
|
|
10 |
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
+
# --- Enhanced Agent for GAIA ---
|
14 |
+
|
15 |
+
|
16 |
+
from smole_agent.agent import SmoleAgent
|
17 |
+
from smole_agent.tools import WebSearchTool, ImageCaptioningTool
|
18 |
+
from smole_agent.tools import Tool
|
19 |
+
|
20 |
class BasicAgent:
|
21 |
def __init__(self):
|
22 |
+
print("BasicAgent initializing with tools...")
|
23 |
+
|
24 |
+
|
25 |
+
self.agent = SmoleAgent.from_pretrained("smol-ai/smole-agent")
|
26 |
+
|
27 |
+
|
28 |
+
self.agent.add_tool(WebSearchTool())
|
29 |
+
self.agent.add_tool(ImageCaptioningTool())
|
30 |
+
|
31 |
+
print("BasicAgent ready.")
|
32 |
+
|
33 |
def __call__(self, question: str) -> str:
|
34 |
+
try:
|
35 |
+
print(f"BasicAgent received question: {question[:50]}...")
|
36 |
+
result = self.agent.run({
|
37 |
+
"question": question,
|
38 |
+
"tools": ["search", "image_captioning"],
|
39 |
+
"context": "Answer using available tools like search or captioning"
|
40 |
+
})
|
41 |
+
return result
|
42 |
+
except Exception as e:
|
43 |
+
print(f"Agent failed: {e}")
|
44 |
+
return f"Error processing question: {e}"
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
class VideoSummaryTool(Tool):
|
49 |
+
name = "video_summary"
|
50 |
+
description = "Summarize the content of a video from a URL."
|
51 |
+
|
52 |
+
def run(self, input: str) -> str:
|
53 |
+
# Just a mock-up
|
54 |
+
return f"Summary of video at {input} (fake response)."
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
|
59 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
60 |
"""
|