emagodev commited on
Commit
6cc4308
·
1 Parent(s): 81917a3

first commit

Browse files
Files changed (6) hide show
  1. .gitignore +190 -0
  2. .python-version +1 -0
  3. agent.py +0 -0
  4. app.py +50 -26
  5. pyproject.toml +14 -0
  6. uv.lock +0 -0
.gitignore ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # General
2
+ .DS_Store
3
+ .AppleDouble
4
+ .LSOverride
5
+
6
+ # Icon must end with two \r
7
+ Icon
8
+
9
+
10
+ # Thumbnails
11
+ ._*
12
+
13
+ # Files that might appear in the root of a volume
14
+ .DocumentRevisions-V100
15
+ .fseventsd
16
+ .Spotlight-V100
17
+ .TemporaryItems
18
+ .Trashes
19
+ .VolumeIcon.icns
20
+ .com.apple.timemachine.donotpresent
21
+
22
+ # Directories potentially created on remote AFP share
23
+ .AppleDB
24
+ .AppleDesktop
25
+ Network Trash Folder
26
+ Temporary Items
27
+ .apdisk
28
+
29
+ # Byte-compiled / optimized / DLL files
30
+ __pycache__/
31
+ *.py[cod]
32
+ *$py.class
33
+
34
+ # C extensions
35
+ *.so
36
+
37
+ # Distribution / packaging
38
+ .Python
39
+ build/
40
+ develop-eggs/
41
+ dist/
42
+ downloads/
43
+ eggs/
44
+ .eggs/
45
+ lib/
46
+ lib64/
47
+ parts/
48
+ sdist/
49
+ var/
50
+ wheels/
51
+ share/python-wheels/
52
+ *.egg-info/
53
+ .installed.cfg
54
+ *.egg
55
+ MANIFEST
56
+
57
+ # PyInstaller
58
+ # Usually these files are written by a python script from a template
59
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
60
+ *.manifest
61
+ *.spec
62
+
63
+ # Installer logs
64
+ pip-log.txt
65
+ pip-delete-this-directory.txt
66
+
67
+ # Unit test / coverage reports
68
+ htmlcov/
69
+ .tox/
70
+ .nox/
71
+ .coverage
72
+ .coverage.*
73
+ .*cache
74
+ nosetests.xml
75
+ coverage.xml
76
+ *.cover
77
+ *.py,cover
78
+ .hypothesis/
79
+ .pytest_cache/
80
+ cover/
81
+
82
+ # Translations
83
+ *.mo
84
+ *.pot
85
+
86
+ # Django stuff:
87
+ *.log
88
+ local_settings.py
89
+ db.sqlite3
90
+ db.sqlite3-journal
91
+
92
+ # Flask stuff:
93
+ instance/
94
+ .webassets-cache
95
+
96
+ # Scrapy stuff:
97
+ .scrapy
98
+
99
+ # Sphinx documentation
100
+ docs/_build/
101
+
102
+ # PyBuilder
103
+ .pybuilder/
104
+ target/
105
+
106
+ # Jupyter Notebook
107
+ .ipynb_checkpoints
108
+
109
+ # IPython
110
+ profile_default/
111
+ ipython_config.py
112
+
113
+ # pyenv
114
+ # For a library or package, you might want to ignore these files since the code is
115
+ # intended to run in multiple environments; otherwise, check them in:
116
+ # .python-version
117
+
118
+ # pipenv
119
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
120
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
121
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
122
+ # install all needed dependencies.
123
+ #Pipfile.lock
124
+
125
+ # poetry
126
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
127
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
128
+ # commonly ignored for libraries.
129
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
130
+ #poetry.lock
131
+
132
+ # pdm
133
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
134
+ #pdm.lock
135
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
136
+ # in version control.
137
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
138
+ .pdm.toml
139
+ .pdm-python
140
+ .pdm-build/
141
+
142
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
143
+ __pypackages__/
144
+
145
+ # Celery stuff
146
+ celerybeat-schedule
147
+ celerybeat.pid
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .venv
155
+ env/
156
+ venv/
157
+ ENV/
158
+ env.bak/
159
+ venv.bak/
160
+
161
+ # Spyder project settings
162
+ .spyderproject
163
+ .spyproject
164
+
165
+ # Rope project settings
166
+ .ropeproject
167
+
168
+ # mkdocs documentation
169
+ /site
170
+
171
+ # mypy
172
+ .mypy_cache/
173
+ .dmypy.json
174
+ dmypy.json
175
+
176
+ # Pyre type checker
177
+ .pyre/
178
+
179
+ # pytype static type analyzer
180
+ .pytype/
181
+
182
+ # Cython debug symbols
183
+ cython_debug/
184
+
185
+ # PyCharm
186
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
187
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
188
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
189
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
190
+ #.idea/
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12
agent.py ADDED
File without changes
app.py CHANGED
@@ -8,27 +8,30 @@ import pandas as pd
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
  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
  """
24
  Fetches all questions, runs the BasicAgent on them, submits all answers,
25
  and displays the results.
26
  """
27
  # --- Determine HF Space Runtime URL and Repo URL ---
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.")
@@ -55,16 +58,16 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
55
  response.raise_for_status()
56
  questions_data = response.json()
57
  if not questions_data:
58
- print("Fetched questions list is empty.")
59
- return "Fetched questions list is empty or invalid format.", None
60
  print(f"Fetched {len(questions_data)} questions.")
61
  except requests.exceptions.RequestException as e:
62
  print(f"Error fetching questions: {e}")
63
  return f"Error fetching questions: {e}", None
64
  except requests.exceptions.JSONDecodeError as e:
65
- print(f"Error decoding JSON response from questions endpoint: {e}")
66
- print(f"Response text: {response.text[:500]}")
67
- return f"Error decoding server response for questions: {e}", None
68
  except Exception as e:
69
  print(f"An unexpected error occurred fetching questions: {e}")
70
  return f"An unexpected error occurred fetching questions: {e}", None
@@ -81,18 +84,36 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
81
  continue
82
  try:
83
  submitted_answer = agent(question_text)
84
- answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
85
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
 
 
 
 
 
 
 
86
  except Exception as e:
87
- print(f"Error running agent on task {task_id}: {e}")
88
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
 
 
 
 
 
89
 
90
  if not answers_payload:
91
  print("Agent did not produce any answers to submit.")
92
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
93
 
94
- # 4. Prepare Submission
95
- submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
 
 
 
 
96
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
97
  print(status_update)
98
 
@@ -162,20 +183,19 @@ with gr.Blocks() as demo:
162
 
163
  run_button = gr.Button("Run Evaluation & Submit All Answers")
164
 
165
- status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
 
 
166
  # Removed max_rows=10 from DataFrame constructor
167
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
168
 
169
- run_button.click(
170
- fn=run_and_submit_all,
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
177
  space_host_startup = os.getenv("SPACE_HOST")
178
- space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
179
 
180
  if space_host_startup:
181
  print(f"✅ SPACE_HOST found: {space_host_startup}")
@@ -183,14 +203,18 @@ if __name__ == "__main__":
183
  else:
184
  print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
185
 
186
- if space_id_startup: # Print repo URLs if SPACE_ID is found
187
  print(f"✅ SPACE_ID found: {space_id_startup}")
188
  print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
189
- print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
 
 
190
  else:
191
- print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")
 
 
192
 
193
- print("-"*(60 + len(" App Starting ")) + "\n")
194
 
195
  print("Launching Gradio Interface for Basic Agent Evaluation...")
196
- demo.launch(debug=True, share=False)
 
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,
28
  and displays the results.
29
  """
30
  # --- Determine HF Space Runtime URL and Repo URL ---
31
+ space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
32
 
33
  if profile:
34
+ username = f"{profile.username}"
35
  print(f"User logged in: {username}")
36
  else:
37
  print("User not logged in.")
 
58
  response.raise_for_status()
59
  questions_data = response.json()
60
  if not questions_data:
61
+ print("Fetched questions list is empty.")
62
+ return "Fetched questions list is empty or invalid format.", None
63
  print(f"Fetched {len(questions_data)} questions.")
64
  except requests.exceptions.RequestException as e:
65
  print(f"Error fetching questions: {e}")
66
  return f"Error fetching questions: {e}", None
67
  except requests.exceptions.JSONDecodeError as e:
68
+ print(f"Error decoding JSON response from questions endpoint: {e}")
69
+ print(f"Response text: {response.text[:500]}")
70
+ return f"Error decoding server response for questions: {e}", None
71
  except Exception as e:
72
  print(f"An unexpected error occurred fetching questions: {e}")
73
  return f"An unexpected error occurred fetching questions: {e}", None
 
84
  continue
85
  try:
86
  submitted_answer = agent(question_text)
87
+ answers_payload.append(
88
+ {"task_id": task_id, "submitted_answer": submitted_answer}
89
+ )
90
+ results_log.append(
91
+ {
92
+ "Task ID": task_id,
93
+ "Question": question_text,
94
+ "Submitted Answer": submitted_answer,
95
+ }
96
+ )
97
  except Exception as e:
98
+ print(f"Error running agent on task {task_id}: {e}")
99
+ results_log.append(
100
+ {
101
+ "Task ID": task_id,
102
+ "Question": question_text,
103
+ "Submitted Answer": f"AGENT ERROR: {e}",
104
+ }
105
+ )
106
 
107
  if not answers_payload:
108
  print("Agent did not produce any answers to submit.")
109
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
110
 
111
+ # 4. Prepare Submission
112
+ submission_data = {
113
+ "username": username.strip(),
114
+ "agent_code": agent_code,
115
+ "answers": answers_payload,
116
+ }
117
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
118
  print(status_update)
119
 
 
183
 
184
  run_button = gr.Button("Run Evaluation & Submit All Answers")
185
 
186
+ status_output = gr.Textbox(
187
+ label="Run Status / Submission Result", lines=5, interactive=False
188
+ )
189
  # Removed max_rows=10 from DataFrame constructor
190
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
191
 
192
+ run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
 
 
 
193
 
194
  if __name__ == "__main__":
195
+ print("\n" + "-" * 30 + " App Starting " + "-" * 30)
196
  # Check for SPACE_HOST and SPACE_ID at startup for information
197
  space_host_startup = os.getenv("SPACE_HOST")
198
+ space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
199
 
200
  if space_host_startup:
201
  print(f"✅ SPACE_HOST found: {space_host_startup}")
 
203
  else:
204
  print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
205
 
206
+ if space_id_startup: # Print repo URLs if SPACE_ID is found
207
  print(f"✅ SPACE_ID found: {space_id_startup}")
208
  print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
209
+ print(
210
+ f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main"
211
+ )
212
  else:
213
+ print(
214
+ "ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined."
215
+ )
216
 
217
+ print("-" * (60 + len(" App Starting ")) + "\n")
218
 
219
  print("Launching Gradio Interface for Basic Agent Evaluation...")
220
+ demo.launch(debug=True, share=False)
pyproject.toml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "final-assignment-template"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "gradio>=5.34.2",
9
+ "llama-index-core>=0.12.43",
10
+ "llama-index-embeddings-huggingface>=0.5.4",
11
+ "llama-index-llms-huggingface-api>=0.5.0",
12
+ "python-dotenv>=1.1.1",
13
+ "requests>=2.32.4",
14
+ ]
uv.lock ADDED
The diff for this file is too large to render. See raw diff