Using uv and first changes
Browse files- .gitignore +174 -0
- .python-version +1 -0
- app.py +66 -26
- pyproject.toml +12 -0
- requirements.txt +0 -2
- uv.lock +0 -0
.gitignore
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# UV
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
#uv.lock
|
102 |
+
|
103 |
+
# poetry
|
104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
106 |
+
# commonly ignored for libraries.
|
107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
108 |
+
#poetry.lock
|
109 |
+
|
110 |
+
# pdm
|
111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
112 |
+
#pdm.lock
|
113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
114 |
+
# in version control.
|
115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
116 |
+
.pdm.toml
|
117 |
+
.pdm-python
|
118 |
+
.pdm-build/
|
119 |
+
|
120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
121 |
+
__pypackages__/
|
122 |
+
|
123 |
+
# Celery stuff
|
124 |
+
celerybeat-schedule
|
125 |
+
celerybeat.pid
|
126 |
+
|
127 |
+
# SageMath parsed files
|
128 |
+
*.sage.py
|
129 |
+
|
130 |
+
# Environments
|
131 |
+
.env
|
132 |
+
.venv
|
133 |
+
env/
|
134 |
+
venv/
|
135 |
+
ENV/
|
136 |
+
env.bak/
|
137 |
+
venv.bak/
|
138 |
+
|
139 |
+
# Spyder project settings
|
140 |
+
.spyderproject
|
141 |
+
.spyproject
|
142 |
+
|
143 |
+
# Rope project settings
|
144 |
+
.ropeproject
|
145 |
+
|
146 |
+
# mkdocs documentation
|
147 |
+
/site
|
148 |
+
|
149 |
+
# mypy
|
150 |
+
.mypy_cache/
|
151 |
+
.dmypy.json
|
152 |
+
dmypy.json
|
153 |
+
|
154 |
+
# Pyre type checker
|
155 |
+
.pyre/
|
156 |
+
|
157 |
+
# pytype static type analyzer
|
158 |
+
.pytype/
|
159 |
+
|
160 |
+
# Cython debug symbols
|
161 |
+
cython_debug/
|
162 |
+
|
163 |
+
# PyCharm
|
164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
168 |
+
#.idea/
|
169 |
+
|
170 |
+
# Ruff stuff:
|
171 |
+
.ruff_cache/
|
172 |
+
|
173 |
+
# PyPI configuration file
|
174 |
+
.pypirc
|
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.12
|
app.py
CHANGED
@@ -1,25 +1,57 @@
|
|
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 ---
|
9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
"""
|
24 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
25 |
and displays the results.
|
@@ -28,22 +60,26 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
28 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
29 |
|
30 |
if profile:
|
31 |
-
username= f"{profile.username}"
|
32 |
print(f"User logged in: {username}")
|
33 |
else:
|
34 |
print("User not logged in.")
|
35 |
return "Please Login to Hugging Face with the button.", None
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
# 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)
|
48 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
49 |
print(agent_code)
|
@@ -73,12 +109,15 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
73 |
results_log = []
|
74 |
answers_payload = []
|
75 |
print(f"Running agent on {len(questions_data)} questions...")
|
|
|
76 |
for item in questions_data:
|
77 |
task_id = item.get("task_id")
|
78 |
question_text = item.get("question")
|
|
|
79 |
if not task_id or question_text is None:
|
80 |
print(f"Skipping item with missing task_id or question: {item}")
|
81 |
continue
|
|
|
82 |
try:
|
83 |
submitted_answer = agent(question_text)
|
84 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
@@ -171,6 +210,7 @@ with gr.Blocks() as demo:
|
|
171 |
outputs=[status_output, results_table]
|
172 |
)
|
173 |
|
|
|
174 |
if __name__ == "__main__":
|
175 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
176 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
|
|
4 |
import pandas as pd
|
5 |
+
from smolagents import (
|
6 |
+
CodeAgent, DuckDuckGoSearchTool, SpeechToTextTool, tool,
|
7 |
+
WikipediaSearchTool, InferenceClientModel
|
8 |
+
)
|
9 |
|
|
|
|
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
+
|
13 |
+
@tool
|
14 |
+
def get_question_file(task_id: str, filename: str) -> None:
|
15 |
+
"""Save locally files required to answer a given question.
|
16 |
+
|
17 |
+
Args:
|
18 |
+
task_id: Question dentifier.
|
19 |
+
filename: Filename to save file as.
|
20 |
+
|
21 |
+
Returns:
|
22 |
+
None, saves file locally.
|
23 |
+
|
24 |
+
Raises:
|
25 |
+
requests.exceptions.RequestException: There was an ambiguous exception
|
26 |
+
that occurred while handling the request.
|
27 |
+
requests.exceptions.JSONDecodeError: Couldn't decode text into json.
|
28 |
+
Exception: Unexpected expection.
|
29 |
+
"""
|
30 |
+
|
31 |
+
try:
|
32 |
+
response = requests.get(
|
33 |
+
f"{DEFAULT_API_URL}/files/{task_id}",
|
34 |
+
timeout=15
|
35 |
+
)
|
36 |
+
response.raise_for_status()
|
37 |
+
open(filename, "wb").write(response.content)
|
38 |
+
|
39 |
+
except requests.exceptions.RequestException as e:
|
40 |
+
print(f"Error fetching question file for {task_id}: {e}")
|
41 |
+
return f"Error fetching question file for {task_id}: {e}", None
|
42 |
+
except requests.exceptions.JSONDecodeError as e:
|
43 |
+
print(f"Error decoding JSON response from files endpoint: {e}")
|
44 |
+
print(f"Response text: {response.text[:500]}")
|
45 |
+
return f"Error decoding server response for file {task_id}: {e}", None
|
46 |
+
except Exception as e:
|
47 |
+
print(f"An unexpected error occurred fetching file for {task_id}: {e}")
|
48 |
+
return (
|
49 |
+
f"An unexpected error occurred fetching file for {task_id}: {e}",
|
50 |
+
None
|
51 |
+
)
|
52 |
+
|
53 |
+
|
54 |
+
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
55 |
"""
|
56 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
57 |
and displays the results.
|
|
|
60 |
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
61 |
|
62 |
if profile:
|
63 |
+
username = f"{profile.username}"
|
64 |
print(f"User logged in: {username}")
|
65 |
else:
|
66 |
print("User not logged in.")
|
67 |
return "Please Login to Hugging Face with the button.", None
|
68 |
|
69 |
+
questions_url = f"{DEFAULT_API_URL}/questions"
|
70 |
+
submit_url = f"{DEFAULT_API_URL}/submit"
|
71 |
+
|
72 |
+
# 1. Instantiate Agent
|
73 |
+
agent = CodeAgent(
|
74 |
+
model=InferenceClientModel("google/paligemma2-3b-mix-448"),
|
75 |
+
tools=[
|
76 |
+
get_question_file,
|
77 |
+
WikipediaSearchTool(),
|
78 |
+
SpeechToTextTool(),
|
79 |
+
DuckDuckGoSearchTool()
|
80 |
+
]
|
81 |
+
)
|
82 |
+
|
83 |
# 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)
|
84 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
85 |
print(agent_code)
|
|
|
109 |
results_log = []
|
110 |
answers_payload = []
|
111 |
print(f"Running agent on {len(questions_data)} questions...")
|
112 |
+
|
113 |
for item in questions_data:
|
114 |
task_id = item.get("task_id")
|
115 |
question_text = item.get("question")
|
116 |
+
|
117 |
if not task_id or question_text is None:
|
118 |
print(f"Skipping item with missing task_id or question: {item}")
|
119 |
continue
|
120 |
+
|
121 |
try:
|
122 |
submitted_answer = agent(question_text)
|
123 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
|
|
210 |
outputs=[status_output, results_table]
|
211 |
)
|
212 |
|
213 |
+
|
214 |
if __name__ == "__main__":
|
215 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
216 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
pyproject.toml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "agents-course-final-assignment"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "Add your description here"
|
5 |
+
readme = "README.md"
|
6 |
+
requires-python = ">=3.10"
|
7 |
+
dependencies = [
|
8 |
+
"gradio>=5.29.1",
|
9 |
+
"pandas>=2.2.3",
|
10 |
+
"requests>=2.32.3",
|
11 |
+
"smolagents>=1.16.1",
|
12 |
+
]
|
requirements.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
gradio
|
2 |
-
requests
|
|
|
|
|
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|