jinv2 commited on
Commit
bc83b7c
·
verified ·
1 Parent(s): af8cde0

Update app.py

Browse files

Fix summarization pipeline and add error handling

Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -5,12 +5,13 @@ import time
5
  try:
6
  client = InferenceClient(model="sshleifer/distilbart-cnn-12-6")
7
  def generate_summary(text):
8
- prompt = f"以正式语气总结:{text}"
9
  for _ in range(3): # 重试3次
10
  try:
11
- response = client.text_generation(prompt, max_length=60)
12
- return response
13
- except Exception:
 
14
  time.sleep(1)
15
  return "网络错误,请稍后重试。"
16
  interface = gr.Interface(
@@ -33,5 +34,4 @@ except Exception as e:
33
  title="MySmartSummary",
34
  description="服务初始化失败"
35
  )
36
- interface.launch()
37
- # This is a test comment to force commit
 
5
  try:
6
  client = InferenceClient(model="sshleifer/distilbart-cnn-12-6")
7
  def generate_summary(text):
8
+ prompt = text # 直接传入文本,无需额外提示
9
  for _ in range(3): # 重试3次
10
  try:
11
+ response = client.summarization(prompt, max_length=60, min_length=10)
12
+ return response[0]['summary_text']
13
+ except Exception as e:
14
+ print(f"尝试失败: {e}")
15
  time.sleep(1)
16
  return "网络错误,请稍后重试。"
17
  interface = gr.Interface(
 
34
  title="MySmartSummary",
35
  description="服务初始化失败"
36
  )
37
+ interface.launch()