Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,32 +12,22 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
host = os.getenv("SPACE_HOST", "jcleee-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
try:
|
| 20 |
-
|
|
|
|
| 21 |
response = requests.post(self.endpoint, json=payload, timeout=60)
|
| 22 |
-
|
| 23 |
-
# βββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
-
# DEBUG LINES:
|
| 25 |
-
print("βΆοΈ POST", self.endpoint)
|
| 26 |
-
print(" payload:", payload)
|
| 27 |
-
print(" status:", response.status_code)
|
| 28 |
-
raw = response.text
|
| 29 |
-
print(" raw response:", raw[:500])
|
| 30 |
-
# ββββββββββββββββββββββββββββββββββββββββββββ
|
| 31 |
-
|
| 32 |
result = response.json()
|
| 33 |
-
|
| 34 |
-
return result["data"][0]
|
| 35 |
-
# if you see e.g. result["predictions"], pull from there instead
|
| 36 |
-
print("β οΈ no `data` key in result, keys are:", result.keys())
|
| 37 |
-
return "null"
|
| 38 |
except Exception as e:
|
| 39 |
return f"Error: {e}"
|
| 40 |
|
|
|
|
| 41 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 42 |
"""
|
| 43 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
host = os.getenv("SPACE_HOST", "jcleee-final-assignment-template.hf.space")
|
| 16 |
+
# <β use /api/predict here
|
| 17 |
+
self.endpoint = f"https://{host}/api/predict"
|
| 18 |
|
| 19 |
def __call__(self, question: str) -> str:
|
| 20 |
try:
|
| 21 |
+
# you usually do NOT need fn_index for a single-Interface app
|
| 22 |
+
payload = {"data": [question]}
|
| 23 |
response = requests.post(self.endpoint, json=payload, timeout=60)
|
| 24 |
+
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
result = response.json()
|
| 26 |
+
return result["data"][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return f"Error: {e}"
|
| 29 |
|
| 30 |
+
|
| 31 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 32 |
"""
|
| 33 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|