Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded a way to prevent crash incase of API error
app.py
CHANGED
@@ -24,7 +24,7 @@ def get_completion(inputs, parameters=None,ENDPOINT_URL=sum_endpoint):
|
|
24 |
"""
|
25 |
This function sends a POST request to a Hugging Face Inference API endpoint and returns the model's output.
|
26 |
|
27 |
-
Args:
|
28 |
inputs (str): The input text to be processed by the model (e.g., for summarization, translation, etc.)
|
29 |
|
30 |
parameters (dict, optional): Additional generation parameters for the model, such as: ### Although it was not used in this program ###
|
@@ -103,10 +103,20 @@ def summarize_ner(text): # I implemented the validation step here because the mo
|
|
103 |
else:
|
104 |
summarized = get_completion(text)
|
105 |
# remember I don't have to define a summarization function because the default mode is summarization
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
# let's perform ner on the summarized text
|
108 |
output = ner(summarized)
|
109 |
return output
|
|
|
110 |
|
111 |
|
112 |
|
|
|
24 |
"""
|
25 |
This function sends a POST request to a Hugging Face Inference API endpoint and returns the model's output.
|
26 |
|
27 |
+
Args:
|
28 |
inputs (str): The input text to be processed by the model (e.g., for summarization, translation, etc.)
|
29 |
|
30 |
parameters (dict, optional): Additional generation parameters for the model, such as: ### Although it was not used in this program ###
|
|
|
103 |
else:
|
104 |
summarized = get_completion(text)
|
105 |
# remember I don't have to define a summarization function because the default mode is summarization
|
106 |
+
|
107 |
+
if isinstance(summarized, list) and 'summary_text' in summarized[0]:
|
108 |
+
summarized = summarized[0]['summary_text']
|
109 |
+
else:
|
110 |
+
return {
|
111 |
+
"text": "⚠️ Unexpected response from summarize.",
|
112 |
+
"entities": []
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
# let's perform ner on the summarized text
|
117 |
output = ner(summarized)
|
118 |
return output
|
119 |
+
|
120 |
|
121 |
|
122 |
|