Spaces:
Runtime error
Runtime error
Ericahooooo
commited on
Commit
•
d5a1d6e
1
Parent(s):
ca64cf3
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,31 @@
|
|
1 |
import gradio as gr, os
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# 加载 BART 模型
|
5 |
model = BartForConditionalGeneration.from_pretrained("models/fnlp/bart-base-chinese")
|
|
|
1 |
import gradio as gr, os
|
2 |
+
from transformers import BartForConditionalGeneration
|
3 |
|
4 |
+
# 加载 BART 模型
|
5 |
+
model = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")
|
6 |
+
|
7 |
+
def generate_summary(file):
|
8 |
+
# 重置文件指针位置
|
9 |
+
file.seek(0)
|
10 |
+
|
11 |
+
# 读取上传的文本文件内容
|
12 |
+
text_content = file.read()
|
13 |
+
|
14 |
+
# 使用模型进行处理(摘要生成)
|
15 |
+
summary_ids = model.generate(text_content, max_length=150, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)
|
16 |
+
summary = model.decode(summary_ids[0], skip_special_tokens=True)
|
17 |
+
|
18 |
+
return summary
|
19 |
+
|
20 |
+
demo = gr.Interface(
|
21 |
+
fn=generate_summary,
|
22 |
+
inputs=gr.File(),
|
23 |
+
outputs="text",
|
24 |
+
live=False
|
25 |
+
)
|
26 |
+
|
27 |
+
# 启动应用
|
28 |
+
demo.launch(share=True)
|
29 |
|
30 |
# 加载 BART 模型
|
31 |
model = BartForConditionalGeneration.from_pretrained("models/fnlp/bart-base-chinese")
|