Mike Jay commited on
Commit
f53079e
·
1 Parent(s): 8772acd

questions data

Browse files
Files changed (4) hide show
  1. .gitignore +222 -0
  2. app.py +26 -10
  3. data/.gitkeep +0 -0
  4. questions.py +66 -0
.gitignore ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Omit HF Questions Data
3
+ data/*.json
4
+
5
+ # omit IDE configs
6
+ .vscode/settings.json
7
+ .gradio
8
+
9
+ # OS clutter
10
+ **/.DS_Store
11
+ **/Thumbs.db
12
+
13
+
14
+ # Byte-compiled / optimized / DLL files
15
+ __pycache__/
16
+ *.py[codz]
17
+ *$py.class
18
+
19
+ # C extensions
20
+ *.so
21
+
22
+ # Distribution / packaging
23
+ .Python
24
+ build/
25
+ develop-eggs/
26
+ dist/
27
+ downloads/
28
+ eggs/
29
+ .eggs/
30
+ lib/
31
+ lib64/
32
+ parts/
33
+ sdist/
34
+ var/
35
+ wheels/
36
+ share/python-wheels/
37
+ *.egg-info/
38
+ .installed.cfg
39
+ *.egg
40
+ MANIFEST
41
+
42
+ # PyInstaller
43
+ # Usually these files are written by a python script from a template
44
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
45
+ *.manifest
46
+ *.spec
47
+
48
+ # Installer logs
49
+ pip-log.txt
50
+ pip-delete-this-directory.txt
51
+
52
+ # Unit test / coverage reports
53
+ htmlcov/
54
+ .tox/
55
+ .nox/
56
+ .coverage
57
+ .coverage.*
58
+ .cache
59
+ nosetests.xml
60
+ coverage.xml
61
+ *.cover
62
+ *.py.cover
63
+ .hypothesis/
64
+ .pytest_cache/
65
+ cover/
66
+
67
+ # Translations
68
+ *.mo
69
+ *.pot
70
+
71
+ # Django stuff:
72
+ *.log
73
+ local_settings.py
74
+ db.sqlite3
75
+ db.sqlite3-journal
76
+
77
+ # Flask stuff:
78
+ instance/
79
+ .webassets-cache
80
+
81
+ # Scrapy stuff:
82
+ .scrapy
83
+
84
+ # Sphinx documentation
85
+ docs/_build/
86
+
87
+ # PyBuilder
88
+ .pybuilder/
89
+ target/
90
+
91
+ # Jupyter Notebook
92
+ .ipynb_checkpoints
93
+
94
+ # IPython
95
+ profile_default/
96
+ ipython_config.py
97
+
98
+ # pyenv
99
+ # For a library or package, you might want to ignore these files since the code is
100
+ # intended to run in multiple environments; otherwise, check them in:
101
+ # .python-version
102
+
103
+ # pipenv
104
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
105
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
106
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
107
+ # install all needed dependencies.
108
+ #Pipfile.lock
109
+
110
+ # UV
111
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
112
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
113
+ # commonly ignored for libraries.
114
+ #uv.lock
115
+
116
+ # poetry
117
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
118
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
119
+ # commonly ignored for libraries.
120
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
121
+ #poetry.lock
122
+ #poetry.toml
123
+
124
+ # pdm
125
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
126
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
127
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
128
+ #pdm.lock
129
+ #pdm.toml
130
+ .pdm-python
131
+ .pdm-build/
132
+
133
+ # pixi
134
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
135
+ #pixi.lock
136
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
137
+ # in the .venv directory. It is recommended not to include this directory in version control.
138
+ .pixi
139
+
140
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
141
+ __pypackages__/
142
+
143
+ # Celery stuff
144
+ celerybeat-schedule
145
+ celerybeat.pid
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ #.idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+
204
+ # Ruff stuff:
205
+ .ruff_cache/
206
+
207
+ # PyPI configuration file
208
+ .pypirc
209
+
210
+ # Cursor
211
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
212
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
213
+ # refer to https://docs.cursor.com/context/ignore-files
214
+ .cursorignore
215
+ .cursorindexingignore
216
+
217
+ # Marimo
218
+ marimo/_static/
219
+ marimo/_lsp/
220
+ __marimo__/
221
+
222
+
app.py CHANGED
@@ -2,7 +2,19 @@
2
 
3
  import os
4
  import gradio as gr
5
- import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  def run_and_submit_all(profile: gr.OAuthProfile | None):
@@ -13,15 +25,19 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
13
  else:
14
  print("User not logged in.")
15
  return "Please Login to Hugging Face with the button.", None
16
- return "Status", pd.DataFrame(
17
- [
18
- {
19
- "Task ID": "task_id",
20
- "Question": "question_text",
21
- "Submitted Answer": "submitted_answer",
22
- }
23
- ]
24
- )
 
 
 
 
25
 
26
 
27
  # --- Build Gradio Interface using Blocks ---
 
2
 
3
  import os
4
  import gradio as gr
5
+
6
+ from questions import get_questions_data
7
+
8
+ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
9
+
10
+ API_URL = DEFAULT_API_URL
11
+ QUESTIONS_URL = f"{API_URL}/questions"
12
+ SUBMIT_URL = f"{API_URL}/submit"
13
+
14
+ SPACE_ID = os.getenv("SPACE_ID")
15
+ if SPACE_ID:
16
+ AGENT_CODE = f"https://huggingface.co/spaces/{SPACE_ID}/tree/main"
17
+ print(f"Agent Code URL: {AGENT_CODE}")
18
 
19
 
20
  def run_and_submit_all(profile: gr.OAuthProfile | None):
 
25
  else:
26
  print("User not logged in.")
27
  return "Please Login to Hugging Face with the button.", None
28
+
29
+ if not SPACE_ID:
30
+ print("SPACE_ID must be set")
31
+ return "SPACE_ID environment variable must be set", None
32
+
33
+ questions_data = get_questions_data(questions_url=QUESTIONS_URL)
34
+ if not questions_data:
35
+ print("Questions list is empty.")
36
+ return "Questions list is empty or invalid format.", None
37
+ print(f"Retrieved {len(questions_data)} questions.")
38
+
39
+ # PLACEHOLDER
40
+ return f"Retrieved {len(questions_data)} questions.", None
41
 
42
 
43
  # --- Build Gradio Interface using Blocks ---
data/.gitkeep ADDED
File without changes
questions.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Module for questions data processing"""
2
+
3
+ import os
4
+ import json
5
+ import requests
6
+
7
+ QUESTIONS_DATA_FILE = "data/questions_data.json"
8
+
9
+
10
+ def _is_exists_questions_data_file() -> bool:
11
+ if os.path.exists(QUESTIONS_DATA_FILE):
12
+ print(f"The file '{QUESTIONS_DATA_FILE}' exists.")
13
+ return True
14
+ print(f"The file '{QUESTIONS_DATA_FILE}' does not exist.")
15
+ return False
16
+
17
+
18
+ def _write_question_data_to_file(questions_data: dict):
19
+ with open(QUESTIONS_DATA_FILE, "w", encoding="utf-8") as json_file:
20
+ json.dump(
21
+ questions_data, json_file, indent=4
22
+ ) # The 'indent=4' parameter pretty-prints the JSON with 4 spaces for indentation.
23
+ print(f"Pretty-printed JSON data written to {QUESTIONS_DATA_FILE}")
24
+
25
+
26
+ def _read_question_data_from_file() -> dict:
27
+ with open(QUESTIONS_DATA_FILE, "r", encoding="utf-8") as json_file:
28
+ questions_data = json.load(json_file)
29
+ return questions_data
30
+
31
+
32
+ def _request_question_data_res(questions_url: str) -> requests.Response:
33
+ try:
34
+ res = requests.get(questions_url, timeout=60)
35
+ res.raise_for_status()
36
+ return res
37
+ except requests.exceptions.HTTPError as e:
38
+ print("HTTP error occurred:", e)
39
+ except requests.exceptions.RequestException as e:
40
+ print("A request error occurred:", e)
41
+ return None
42
+
43
+
44
+ def _json_question_data_from_res(res: requests.Response) -> dict:
45
+ try:
46
+ questions_data = res.json()
47
+ return questions_data
48
+ except requests.exceptions.JSONDecodeError as e:
49
+ questions_data = None
50
+ print(f"Error decoding JSON response from questions endpoint: {e}")
51
+ print(f"Response text: {res.text[:500]}")
52
+ return None
53
+
54
+
55
+ def get_questions_data(questions_url: str) -> dict:
56
+ """Get Questions Data"""
57
+ if _is_exists_questions_data_file():
58
+ questions_data = _read_question_data_from_file()
59
+ return questions_data
60
+ res = _request_question_data_res(questions_url=questions_url)
61
+ if res:
62
+ questions_data = _json_question_data_from_res(res)
63
+ if questions_data:
64
+ _write_question_data_to_file(questions_data=questions_data)
65
+ return questions_data
66
+ return None