Andrei Sferdian commited on
Commit ·
cdb442d
1
Parent(s): 531d1d4
Evaluating ReAct model with DuckDuckGo tool
Browse files- app.py +11 -19
- requirements.txt +12 -1
app.py
CHANGED
|
@@ -3,25 +3,15 @@ import os
|
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import requests
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 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 |
-
|
| 18 |
-
def __call__(self, question: str) -> str:
|
| 19 |
-
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 20 |
-
fixed_answer = "This is a default answer."
|
| 21 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 22 |
-
return fixed_answer
|
| 23 |
-
|
| 24 |
-
|
| 25 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 26 |
"""
|
| 27 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
@@ -42,11 +32,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 42 |
submit_url = f"{api_url}/submit"
|
| 43 |
|
| 44 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 45 |
-
|
| 46 |
-
agent = BasicAgent()
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"Error instantiating agent: {e}")
|
| 49 |
-
return f"Error initializing agent: {e}", None
|
| 50 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 51 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 52 |
print(agent_code)
|
|
@@ -83,7 +69,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 83 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 84 |
continue
|
| 85 |
try:
|
| 86 |
-
submitted_answer = agent(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
answers_payload.append(
|
| 88 |
{"task_id": task_id, "submitted_answer": submitted_answer}
|
| 89 |
)
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import requests
|
| 6 |
+
from langchain_core.messages import HumanMessage
|
| 7 |
+
|
| 8 |
+
from agent import agent
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 16 |
"""
|
| 17 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 32 |
submit_url = f"{api_url}/submit"
|
| 33 |
|
| 34 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 35 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 37 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 38 |
print(agent_code)
|
|
|
|
| 69 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 70 |
continue
|
| 71 |
try:
|
| 72 |
+
submitted_answer = agent.invoke(
|
| 73 |
+
{
|
| 74 |
+
"messages": [
|
| 75 |
+
HumanMessage(content=question_text),
|
| 76 |
+
],
|
| 77 |
+
}
|
| 78 |
+
)
|
| 79 |
answers_payload.append(
|
| 80 |
{"task_id": task_id, "submitted_answer": submitted_answer}
|
| 81 |
)
|
requirements.txt
CHANGED
|
@@ -4,12 +4,13 @@ aiohttp==3.11.18
|
|
| 4 |
aiosignal==1.3.2
|
| 5 |
annotated-types==0.7.0
|
| 6 |
anyio==4.9.0
|
| 7 |
-
async-timeout==
|
| 8 |
attrs==25.3.0
|
| 9 |
beautifulsoup4==4.13.4
|
| 10 |
certifi==2025.4.26
|
| 11 |
charset-normalizer==3.4.1
|
| 12 |
click==8.1.8
|
|
|
|
| 13 |
distro==1.9.0
|
| 14 |
duckduckgo_search==8.0.1
|
| 15 |
exceptiongroup==1.2.2
|
|
@@ -20,18 +21,23 @@ frozenlist==1.6.0
|
|
| 20 |
fsspec==2025.3.2
|
| 21 |
gradio==5.27.0
|
| 22 |
gradio_client==1.9.0
|
|
|
|
| 23 |
groovy==0.1.2
|
| 24 |
h11==0.16.0
|
| 25 |
httpcore==1.0.9
|
| 26 |
httpx==0.28.1
|
|
|
|
| 27 |
huggingface-hub==0.30.2
|
| 28 |
idna==3.10
|
| 29 |
Jinja2==3.1.6
|
| 30 |
jiter==0.9.0
|
| 31 |
jsonpatch==1.33
|
| 32 |
jsonpointer==3.0.0
|
|
|
|
|
|
|
| 33 |
langchain-core==0.3.56
|
| 34 |
langchain-openai==0.3.14
|
|
|
|
| 35 |
langchain-together==0.3.0
|
| 36 |
langgraph==0.3.34
|
| 37 |
langgraph-checkpoint==2.0.24
|
|
@@ -42,8 +48,10 @@ lxml==5.4.0
|
|
| 42 |
markdown-it-py==3.0.0
|
| 43 |
markdownify==1.1.0
|
| 44 |
MarkupSafe==3.0.2
|
|
|
|
| 45 |
mdurl==0.1.2
|
| 46 |
multidict==6.4.3
|
|
|
|
| 47 |
numpy==2.2.5
|
| 48 |
openai==1.76.0
|
| 49 |
orjson==3.10.16
|
|
@@ -54,6 +62,7 @@ pillow==11.2.1
|
|
| 54 |
primp==0.15.0
|
| 55 |
propcache==0.3.1
|
| 56 |
pydantic==2.11.3
|
|
|
|
| 57 |
pydantic_core==2.33.1
|
| 58 |
pydub==0.25.1
|
| 59 |
Pygments==2.19.1
|
|
@@ -73,12 +82,14 @@ shellingham==1.5.4
|
|
| 73 |
six==1.17.0
|
| 74 |
sniffio==1.3.1
|
| 75 |
soupsieve==2.7
|
|
|
|
| 76 |
starlette==0.46.2
|
| 77 |
tenacity==9.1.2
|
| 78 |
tiktoken==0.9.0
|
| 79 |
tomlkit==0.13.2
|
| 80 |
tqdm==4.67.1
|
| 81 |
typer==0.15.2
|
|
|
|
| 82 |
typing-inspection==0.4.0
|
| 83 |
typing_extensions==4.13.2
|
| 84 |
tzdata==2025.2
|
|
|
|
| 4 |
aiosignal==1.3.2
|
| 5 |
annotated-types==0.7.0
|
| 6 |
anyio==4.9.0
|
| 7 |
+
async-timeout==4.0.3
|
| 8 |
attrs==25.3.0
|
| 9 |
beautifulsoup4==4.13.4
|
| 10 |
certifi==2025.4.26
|
| 11 |
charset-normalizer==3.4.1
|
| 12 |
click==8.1.8
|
| 13 |
+
dataclasses-json==0.6.7
|
| 14 |
distro==1.9.0
|
| 15 |
duckduckgo_search==8.0.1
|
| 16 |
exceptiongroup==1.2.2
|
|
|
|
| 21 |
fsspec==2025.3.2
|
| 22 |
gradio==5.27.0
|
| 23 |
gradio_client==1.9.0
|
| 24 |
+
greenlet==3.2.1
|
| 25 |
groovy==0.1.2
|
| 26 |
h11==0.16.0
|
| 27 |
httpcore==1.0.9
|
| 28 |
httpx==0.28.1
|
| 29 |
+
httpx-sse==0.4.0
|
| 30 |
huggingface-hub==0.30.2
|
| 31 |
idna==3.10
|
| 32 |
Jinja2==3.1.6
|
| 33 |
jiter==0.9.0
|
| 34 |
jsonpatch==1.33
|
| 35 |
jsonpointer==3.0.0
|
| 36 |
+
langchain==0.3.24
|
| 37 |
+
langchain-community==0.3.22
|
| 38 |
langchain-core==0.3.56
|
| 39 |
langchain-openai==0.3.14
|
| 40 |
+
langchain-text-splitters==0.3.8
|
| 41 |
langchain-together==0.3.0
|
| 42 |
langgraph==0.3.34
|
| 43 |
langgraph-checkpoint==2.0.24
|
|
|
|
| 48 |
markdown-it-py==3.0.0
|
| 49 |
markdownify==1.1.0
|
| 50 |
MarkupSafe==3.0.2
|
| 51 |
+
marshmallow==3.26.1
|
| 52 |
mdurl==0.1.2
|
| 53 |
multidict==6.4.3
|
| 54 |
+
mypy_extensions==1.1.0
|
| 55 |
numpy==2.2.5
|
| 56 |
openai==1.76.0
|
| 57 |
orjson==3.10.16
|
|
|
|
| 62 |
primp==0.15.0
|
| 63 |
propcache==0.3.1
|
| 64 |
pydantic==2.11.3
|
| 65 |
+
pydantic-settings==2.9.1
|
| 66 |
pydantic_core==2.33.1
|
| 67 |
pydub==0.25.1
|
| 68 |
Pygments==2.19.1
|
|
|
|
| 82 |
six==1.17.0
|
| 83 |
sniffio==1.3.1
|
| 84 |
soupsieve==2.7
|
| 85 |
+
SQLAlchemy==2.0.40
|
| 86 |
starlette==0.46.2
|
| 87 |
tenacity==9.1.2
|
| 88 |
tiktoken==0.9.0
|
| 89 |
tomlkit==0.13.2
|
| 90 |
tqdm==4.67.1
|
| 91 |
typer==0.15.2
|
| 92 |
+
typing-inspect==0.9.0
|
| 93 |
typing-inspection==0.4.0
|
| 94 |
typing_extensions==4.13.2
|
| 95 |
tzdata==2025.2
|