Spaces:
Sleeping
Sleeping
Shreya Pal commited on
Commit ·
84f2df9
1
Parent(s): 0d79c56
Extract upstream Hugging Face API errors natively dropping into UI fallback wrapper
Browse files- server/app.py +8 -0
server/app.py
CHANGED
|
@@ -136,6 +136,14 @@ Respond with exactly this format:
|
|
| 136 |
|
| 137 |
raw = response.json()
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
if isinstance(raw, list):
|
| 140 |
text_out = raw[0].get("generated_text", "")
|
| 141 |
else:
|
|
|
|
| 136 |
|
| 137 |
raw = response.json()
|
| 138 |
|
| 139 |
+
if response.status_code != 200 or ("error" in raw and isinstance(raw, dict)):
|
| 140 |
+
error_msg = raw.get("error", str(raw))
|
| 141 |
+
return {
|
| 142 |
+
"decision": "flag",
|
| 143 |
+
"confidence": 0.5,
|
| 144 |
+
"explanation": f"HuggingFace API Error: {error_msg}"
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
if isinstance(raw, list):
|
| 148 |
text_out = raw[0].get("generated_text", "")
|
| 149 |
else:
|