Spaces:
Sleeping
Sleeping
Update app.py
Browse filesHandle generated_text for summarization output
app.py
CHANGED
|
@@ -16,7 +16,13 @@ try:
|
|
| 16 |
try:
|
| 17 |
response = client.summarization(text)
|
| 18 |
print(f"API Response: {response}")
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
error_details = traceback.format_exc()
|
| 22 |
print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")
|
|
|
|
| 16 |
try:
|
| 17 |
response = client.summarization(text)
|
| 18 |
print(f"API Response: {response}")
|
| 19 |
+
# 优先使用 generated_text,如果为空则尝试 summary_text
|
| 20 |
+
if hasattr(response, 'generated_text') and response.generated_text:
|
| 21 |
+
return response.generated_text
|
| 22 |
+
elif hasattr(response, 'summary_text') and response.summary_text:
|
| 23 |
+
return response.summary_text
|
| 24 |
+
else:
|
| 25 |
+
return "摘要生成失败,属性缺失。"
|
| 26 |
except Exception as e:
|
| 27 |
error_details = traceback.format_exc()
|
| 28 |
print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")
|