jproman commited on
Commit
05919ff
·
1 Parent(s): d05b76d

initial commit

Browse files
Files changed (7) hide show
  1. .gitignore +174 -0
  2. .vscode/launch.json +16 -0
  3. agent.py +19 -0
  4. app.py +9 -26
  5. assignment_utils.py +32 -0
  6. config.py +4 -0
  7. requirements.txt +2 -1
.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
.vscode/launch.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+
8
+ {
9
+ "name": "Python Debugger: Current File",
10
+ "type": "debugpy",
11
+ "request": "launch",
12
+ "program": "${file}",
13
+ "console": "integratedTerminal"
14
+ }
15
+ ]
16
+ }
agent.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from assignment_utils import getQuestionByPos
3
+
4
+
5
+ class Agent:
6
+ def __init__(self):
7
+ pass
8
+
9
+ def invoke(self, question):
10
+ fixed_answer = "This is a default answer."
11
+ return fixed_answer
12
+
13
+
14
+ if __name__ == "__main__":
15
+ agent = Agent()
16
+ question = getQuestionByPos(0)
17
+ print(question)
18
+ response = agent.invoke(question['question'])
19
+ print(response)
app.py CHANGED
@@ -4,22 +4,9 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
7
- ## jproman
8
-
9
- # (Keep Constants as is)
10
- # --- Constants ---
11
- DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
-
13
- # --- Basic Agent Definition ---
14
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
- class BasicAgent:
16
- def __init__(self):
17
- print("BasicAgent initialized.")
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
  def run_and_submit_all( profile: gr.OAuthProfile | None):
25
  """
@@ -36,13 +23,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
36
  print("User not logged in.")
37
  return "Please Login to Hugging Face with the button.", None
38
 
39
- api_url = DEFAULT_API_URL
40
- questions_url = f"{api_url}/questions"
41
- submit_url = f"{api_url}/submit"
42
-
43
  # 1. Instantiate Agent ( modify this part to create your agent)
44
  try:
45
- agent = BasicAgent()
46
  except Exception as e:
47
  print(f"Error instantiating agent: {e}")
48
  return f"Error initializing agent: {e}", None
@@ -51,9 +34,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
51
  print(agent_code)
52
 
53
  # 2. Fetch Questions
54
- print(f"Fetching questions from: {questions_url}")
55
  try:
56
- response = requests.get(questions_url, timeout=15)
57
  response.raise_for_status()
58
  questions_data = response.json()
59
  if not questions_data:
@@ -82,7 +65,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
82
  print(f"Skipping item with missing task_id or question: {item}")
83
  continue
84
  try:
85
- submitted_answer = agent(question_text)
86
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
87
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
88
  except Exception as e:
@@ -99,9 +82,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
99
  print(status_update)
100
 
101
  # 5. Submit
102
- print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
103
  try:
104
- response = requests.post(submit_url, json=submission_data, timeout=60)
105
  response.raise_for_status()
106
  result_data = response.json()
107
  final_status = (
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ import config
8
+ from agent import Agent
9
+
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def run_and_submit_all( profile: gr.OAuthProfile | None):
12
  """
 
23
  print("User not logged in.")
24
  return "Please Login to Hugging Face with the button.", None
25
 
 
 
 
 
26
  # 1. Instantiate Agent ( modify this part to create your agent)
27
  try:
28
+ agent = Agent()
29
  except Exception as e:
30
  print(f"Error instantiating agent: {e}")
31
  return f"Error initializing agent: {e}", None
 
34
  print(agent_code)
35
 
36
  # 2. Fetch Questions
37
+ print(f"Fetching questions from: {config.questionsUrl}")
38
  try:
39
+ response = requests.get(config.questionsUrl, timeout=15)
40
  response.raise_for_status()
41
  questions_data = response.json()
42
  if not questions_data:
 
65
  print(f"Skipping item with missing task_id or question: {item}")
66
  continue
67
  try:
68
+ submitted_answer = agent.invoke(question_text)
69
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
70
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
71
  except Exception as e:
 
82
  print(status_update)
83
 
84
  # 5. Submit
85
+ print(f"Submitting {len(answers_payload)} answers to: {config.submitUrl}")
86
  try:
87
+ response = requests.post(config.submitUrl, json=submission_data, timeout=60)
88
  response.raise_for_status()
89
  result_data = response.json()
90
  final_status = (
assignment_utils.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+
4
+ import config
5
+
6
+
7
+ def getQuestions():
8
+ try:
9
+ response = requests.get(config.questionsUrl, timeout=15)
10
+ response.raise_for_status()
11
+ questions_data = response.json()
12
+ if not questions_data:
13
+ print("Fetched questions list is empty.")
14
+ raise Exception("Fetched questions list is empty")
15
+ print(f"Fetched {len(questions_data)} questions.")
16
+ return questions_data
17
+ except Exception as e:
18
+ print(f"An unexpected error occurred fetching questions: {e}")
19
+ return None
20
+
21
+ def getQuestionByPos(i):
22
+ questions = getQuestions()
23
+ return questions[i]
24
+
25
+ def printQuestions():
26
+ for i,question in enumerate(getQuestions()):
27
+ print(f"{i+1}: {question['question']} {'(File: ' + question['file_name'] + ')' if question['file_name'] else ''}")
28
+
29
+ if __name__ == "__main__":
30
+ questions = getQuestions()
31
+ printQuestions()
32
+
config.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ baseApiUrl = "https://agents-course-unit4-scoring.hf.space"
3
+ questionsUrl = f"{baseApiUrl}/questions"
4
+ submitUrl = f"{baseApiUrl}/submit"
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio
2
- requests
 
 
1
  gradio
2
+ requests
3
+ gradio[oauth]