Spaces:
Sleeping
Sleeping
implemented simple web search logic
Browse files- .gitignore +3 -0
- app.py +19 -6
- requirements.txt +2 -1
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
venv/
|
| 3 |
+
__pycache__/
|
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
import os
|
| 2 |
-
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 +16,21 @@ 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 |
-
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
fixed_answer = "This is a default answer."
|
| 19 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 20 |
-
return fixed_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import requests
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
|
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
print("BasicAgent initialized.")
|
| 19 |
+
search_tool = DuckDuckGoSearchTool()
|
| 20 |
+
model = InferenceClientModel()
|
| 21 |
+
self.agent = CodeAgent(
|
| 22 |
+
model=model,
|
| 23 |
+
tools=[search_tool],
|
| 24 |
+
)
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
+
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 27 |
+
# fixed_answer = "This is a default answer."
|
| 28 |
+
# print(f"Agent returning fixed answer: {fixed_answer}")
|
| 29 |
+
# return fixed_answer
|
| 30 |
+
response = self.agent.run(question)
|
| 31 |
+
return str(response) # run returns an object, we must cast it to str
|
| 32 |
+
|
| 33 |
+
|
| 34 |
|
| 35 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 36 |
"""
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
gradio
|
| 2 |
-
requests
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
+
requests
|
| 3 |
+
smolagents
|