Spaces:
Sleeping
Sleeping
Delete textsumm.py
Browse files- textsumm.py +0 -19
textsumm.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
# textsumm.py
|
2 |
-
from transformers import pipeline
|
3 |
-
|
4 |
-
# 使用 pegasus 中文摘要模型
|
5 |
-
summarizer = pipeline("summarization", model="IDEA-CCNL/Randeng-Pegasus-523M-Summary-Chinese")
|
6 |
-
|
7 |
-
def 摘要(text):
|
8 |
-
"""
|
9 |
-
傳入中文長文本,回傳中文摘要
|
10 |
-
"""
|
11 |
-
# Pegasus 最佳 max_length < 256,如需長摘要可微調
|
12 |
-
try:
|
13 |
-
result = summarizer(text, max_length=128, min_length=30, do_sample=False)
|
14 |
-
if isinstance(result, list) and len(result) > 0:
|
15 |
-
return result[0]['summary_text']
|
16 |
-
else:
|
17 |
-
return "❌ 無法產生摘要"
|
18 |
-
except Exception as e:
|
19 |
-
return f"❌ 摘要失敗: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|