Spaces:
Sleeping
Sleeping
Update api_client.py
Browse files- api_client.py +18 -0
api_client.py
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 4 |
+
|
| 5 |
+
def fetch_questions():
|
| 6 |
+
response = requests.get(f"{DEFAULT_API_URL}/questions", timeout=15)
|
| 7 |
+
response.raise_for_status()
|
| 8 |
+
return response.json()
|
| 9 |
+
|
| 10 |
+
def submit_answers(username, agent_code, answers):
|
| 11 |
+
payload = {
|
| 12 |
+
"username": username.strip(),
|
| 13 |
+
"agent_code": agent_code,
|
| 14 |
+
"answers": answers
|
| 15 |
+
}
|
| 16 |
+
response = requests.post(f"{DEFAULT_API_URL}/submit", json=payload, timeout=60)
|
| 17 |
+
response.raise_for_status()
|
| 18 |
+
return response.json()
|