Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,13 +12,29 @@ 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 |
-
|
|
|
|
| 16 |
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
try:
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
result = response.json()
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"Error: {e}"
|
| 24 |
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
host = os.getenv("SPACE_HOST", "jcleee-first-agent-template.hf.space")
|
| 16 |
+
self.endpoint = f"https://{host}/run/predict"
|
| 17 |
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
try:
|
| 20 |
+
payload = {"data": [question], "fn_index": 0}
|
| 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 |
+
if "data" in result:
|
| 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 |
|