jarguello76 commited on
Commit
d05591b
·
verified ·
1 Parent(s): 33adf36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -30,7 +30,11 @@ class HuggingFaceInferenceWrapper:
30
  # Call inference API with raw_response=True to get the raw Response object
31
  response = self.inference_api(inputs=prompt, raw_response=True)
32
 
33
- # Parse the JSON response
 
 
 
 
34
  if hasattr(response, 'json'):
35
  json_response = response.json()
36
  # Extract the relevant information from the JSON response
@@ -42,7 +46,12 @@ class HuggingFaceInferenceWrapper:
42
  return json_response.get('generated_text', '').strip()
43
 
44
  # Fallback: return the raw response text if JSON parsing fails
45
- return response.text.strip()
 
 
 
 
 
46
 
47
 
48
 
 
30
  # Call inference API with raw_response=True to get the raw Response object
31
  response = self.inference_api(inputs=prompt, raw_response=True)
32
 
33
+ # Check if the response is a string
34
+ if isinstance(response, str):
35
+ return response.strip()
36
+
37
+ # Parse the JSON response if the response is not a string
38
  if hasattr(response, 'json'):
39
  json_response = response.json()
40
  # Extract the relevant information from the JSON response
 
46
  return json_response.get('generated_text', '').strip()
47
 
48
  # Fallback: return the raw response text if JSON parsing fails
49
+ if hasattr(response, 'text'):
50
+ return response.text.strip()
51
+
52
+ # If none of the above conditions are met, return an empty string or handle the error appropriately
53
+ return ""
54
+
55
 
56
 
57