Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,15 +27,23 @@ class HuggingFaceInferenceWrapper:
|
|
27 |
self.inference_api = inference_api
|
28 |
|
29 |
def generate(self, prompt: str, **kwargs) -> str:
|
30 |
-
# Call inference API
|
31 |
-
response = self.inference_api(inputs=prompt)
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
#
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
|
41 |
|
|
|
27 |
self.inference_api = inference_api
|
28 |
|
29 |
def generate(self, prompt: str, **kwargs) -> str:
|
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
|
37 |
+
# This depends on the structure of the JSON response from the API
|
38 |
+
# For example, if the response contains a 'generated_text' field:
|
39 |
+
if isinstance(json_response, list) and len(json_response) > 0:
|
40 |
+
return json_response[0].get('generated_text', '').strip()
|
41 |
+
elif isinstance(json_response, dict):
|
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 |
|
49 |
|