Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,43 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
-
import
|
7 |
-
from smolagents import DuckDuckGoSearchTool
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
# --- Basic Agent Definition ---
|
13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
print("BasicAgent initialized.")
|
17 |
-
self.
|
|
|
18 |
def __call__(self, question: str) -> str:
|
19 |
-
print(f"Agent received question
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return answer
|
23 |
|
24 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagents.tools import duckduckgosearch
|
|
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
9 |
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 |
+
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
print("BasicAgent initialized.")
|
17 |
+
self.search = duckduckgosearch
|
18 |
+
|
19 |
def __call__(self, question: str) -> str:
|
20 |
+
print(f"Agent received question: {question}")
|
21 |
+
|
22 |
+
try:
|
23 |
+
# Perform the search; returns a list of results
|
24 |
+
results = self.search(question)
|
25 |
+
if not results:
|
26 |
+
return "No results found for that query."
|
27 |
+
|
28 |
+
# Results is a sequence of dicts, assume it has 'title' and 'snippet'
|
29 |
+
top = results[0]
|
30 |
+
title = top.get("title", "No title")
|
31 |
+
snippet = top.get("snippet", "").strip()
|
32 |
+
link = top.get("link", "")
|
33 |
+
|
34 |
+
# Compose a clean answer
|
35 |
+
answer = f"**{title}**\n{snippet}"
|
36 |
+
if link:
|
37 |
+
answer += f"\nSource: {link}"
|
38 |
+
|
39 |
+
except Exception as e:
|
40 |
+
answer = f"Sorry, I couldn't fetch results due to: {e}"
|
41 |
+
|
42 |
+
print(f"Agent returning answer: {answer}")
|
43 |
return answer
|
44 |
|
45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|