binhqd commited on
Commit
6775e28
·
1 Parent(s): 8f5b2eb

Fix: use .get() instead of .pop() for safer data access

Browse files
Files changed (1) hide show
  1. 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.pop("inputs", data)
87
 
88
  # Get additional parameters from top level
89
- description = data.pop("description", "")
90
- generation_args = data.pop("generation_args", {})
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 in inputs"}
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