Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import time | |
| try: | |
| client = InferenceClient(model="sshleifer/distilbart-cnn-12-6") | |
| def generate_summary(text): | |
| prompt = f"以正式语气总结:{text}" | |
| for _ in range(3): # 重试3次 | |
| try: | |
| response = client.text_generation(prompt, max_length=60) | |
| return response | |
| except Exception: | |
| 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() |