Fix: use .get() instead of .pop() for safer data access
Browse files- handler.py +5 -5
handler.py
CHANGED
|
@@ -83,11 +83,11 @@ class EndpointHandler:
|
|
| 83 |
}
|
| 84 |
"""
|
| 85 |
# Extract inputs (HF always provides this key)
|
| 86 |
-
inputs = data.
|
| 87 |
|
| 88 |
# Get additional parameters from top level
|
| 89 |
-
description = data.
|
| 90 |
-
generation_args = data.
|
| 91 |
|
| 92 |
# Parse inputs
|
| 93 |
if isinstance(inputs, dict):
|
|
@@ -99,10 +99,10 @@ class EndpointHandler:
|
|
| 99 |
text = inputs
|
| 100 |
else:
|
| 101 |
# Try to convert to string
|
| 102 |
-
text = str(inputs)
|
| 103 |
|
| 104 |
if not text:
|
| 105 |
-
return {"error": "No text provided
|
| 106 |
prompt = description + "\n" + text
|
| 107 |
|
| 108 |
# If running in fake mode (quick smoke test), synthesize a sine tone
|
|
|
|
| 83 |
}
|
| 84 |
"""
|
| 85 |
# Extract inputs (HF always provides this key)
|
| 86 |
+
inputs = data.get("inputs", "")
|
| 87 |
|
| 88 |
# Get additional parameters from top level
|
| 89 |
+
description = data.get("description", "")
|
| 90 |
+
generation_args = data.get("generation_args", {})
|
| 91 |
|
| 92 |
# Parse inputs
|
| 93 |
if isinstance(inputs, dict):
|
|
|
|
| 99 |
text = inputs
|
| 100 |
else:
|
| 101 |
# Try to convert to string
|
| 102 |
+
text = str(inputs) if inputs else ""
|
| 103 |
|
| 104 |
if not text:
|
| 105 |
+
return {"error": f"No text provided. Received: {data}"}
|
| 106 |
prompt = description + "\n" + text
|
| 107 |
|
| 108 |
# If running in fake mode (quick smoke test), synthesize a sine tone
|