aaron888 commited on
Commit
338bb04
·
verified ·
1 Parent(s): 6f48385

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -9,10 +9,17 @@ def summarize(input_text):
9
  # 使用模型生成摘要
10
  summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
11
  return summary[0]['summary_text']
12
-
 
 
 
 
 
 
13
  # 使用 Gradio 构建前端
14
  gr.close_all() # 关闭其他可能在运行的 Gradio 应用
15
- demo = gr.Interface(fn=summarize, inputs="text", outputs="text", title="Text Summarization with distilbart-cnn-12-6")
 
16
 
17
  # 启动 Gradio 应用
18
  demo.launch()
 
9
  # 使用模型生成摘要
10
  summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
11
  return summary[0]['summary_text']
12
+
13
+ def summarize_with_error_handling(input_text):
14
+ try:
15
+ return summarize(input_text)
16
+ except Exception as e:
17
+ return f"An error occurred: {str(e)}"
18
+
19
  # 使用 Gradio 构建前端
20
  gr.close_all() # 关闭其他可能在运行的 Gradio 应用
21
+ demo = gr.Interface(fn=summarize_with_error_handling, inputs="text", outputs="text", title="Text Summarization with distilbart-cnn-12-6")
22
+
23
 
24
  # 启动 Gradio 应用
25
  demo.launch()