jarguello76 commited on
Commit
35b6d91
·
verified ·
1 Parent(s): 52a1284

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -27,19 +27,15 @@ class HuggingFaceInferenceWrapper:
27
  self.inference_api = inference_api
28
 
29
  def generate(self, prompt: str, **kwargs) -> str:
30
- # Request raw response and handle JSON decoding
31
- response = self.inference_api(inputs=prompt, raw_response=True)
32
- result_json = response.json()
33
-
34
- # Handle both plain text and chat-style model formats
35
- if isinstance(result_json, dict):
36
- if "generated_text" in result_json:
37
- return result_json["generated_text"].strip()
38
- elif "outputs" in result_json and isinstance(result_json["outputs"], str):
39
- return result_json["outputs"].strip()
40
-
41
- # If unknown format, fallback
42
- return str(result_json)
43
 
44
 
45
 
 
27
  self.inference_api = inference_api
28
 
29
  def generate(self, prompt: str, **kwargs) -> str:
30
+ # Call inference API - returns string directly
31
+ response = self.inference_api(inputs=prompt)
32
+ if isinstance(response, str):
33
+ return response.strip()
34
+ elif hasattr(response, 'text'):
35
+ return response.text.strip()
36
+ else:
37
+ # Handle JSON response
38
+ return str(response)
 
 
 
 
39
 
40
 
41