Added smolagents.
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 ---
|
@@ -12,12 +13,21 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
15 |
-
print("BasicAgent initialized.")
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
@@ -142,7 +152,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
142 |
|
143 |
# --- Build Gradio Interface using Blocks ---
|
144 |
with gr.Blocks() as demo:
|
145 |
-
gr.Markdown("# Basic Agent Evaluation Runner
|
146 |
gr.Markdown(
|
147 |
"""
|
148 |
**Instructions:**
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagents import Agent # Import the smolagents library [[1]]
|
7 |
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
|
|
13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
+
print("BasicAgent initialized with smolagents.")
|
17 |
+
self.agent = Agent() # Initialize smolagents' Agent [[2]]
|
18 |
+
|
19 |
def __call__(self, question: str) -> str:
|
20 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
21 |
+
|
22 |
+
# Perform a web search using smolagents
|
23 |
+
try:
|
24 |
+
search_result = self.agent.search(question) # Use smolagents' search capability [[1]]
|
25 |
+
answer = f"Search result for '{question[:50]}...': {search_result}"
|
26 |
+
except Exception as e:
|
27 |
+
answer = f"Error during search: {e}"
|
28 |
+
|
29 |
+
print(f"Agent returning answer: {answer}")
|
30 |
+
return answer
|
31 |
|
32 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
33 |
"""
|
|
|
152 |
|
153 |
# --- Build Gradio Interface using Blocks ---
|
154 |
with gr.Blocks() as demo:
|
155 |
+
gr.Markdown("# Basic Agent Evaluation Runner")
|
156 |
gr.Markdown(
|
157 |
"""
|
158 |
**Instructions:**
|