Spaces:
Sleeping
Sleeping
File size: 1,421 Bytes
8c09497 6ef0b07 8c09497 6ef0b07 9b18ba6 0a32d05 bc83b7c 6ef0b07 bc83b7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from huggingface_hub import InferenceClient
import time
try:
client = InferenceClient(model="sshleifer/distilbart-cnn-12-6")
def generate_summary(text):
for _ in range(3): # 重试3次
try:
# 尝试直接传递文本作为位置参数
response = client.summarization(text)
return response[0]['summary_text'] if response and 'summary_text' in response[0] else "摘要生成失败,请重试。"
except Exception as e:
print(f"尝试失败: {e}")
time.sleep(1)
return "网络错误,请稍后重试。"
interface = gr.Interface(
fn=generate_summary,
inputs=gr.Textbox(lines=5, placeholder="输入文档内容..."),
outputs="text",
title="MySmartSummary",
description="在线智能文档摘要工具,支持中文",
examples=[
["今天我们讨论了2025年的项目计划,包括产品发布、市场推广和预算分配。"]
],
css="body {background-color: #f0f0f0; font-family: Arial;}"
)
except Exception as e:
print(f"初始化错误: {e}")
interface = gr.Interface(
fn=lambda x: f"服务暂不可用,错误: {e}",
inputs="text",
outputs="text",
title="MySmartSummary",
description="服务初始化失败"
)
interface.launch() |