Spaces:
Build error
Build error
hellopahe
commited on
Commit
·
f1ae6c0
1
Parent(s):
6a0cb69
add custom siblings
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import math, torch, gradio as gr
|
2 |
|
3 |
from lex_rank import LexRank
|
4 |
-
from
|
5 |
from lex_rank_L12 import LexRankL12
|
6 |
from sentence_transformers import SentenceTransformer, util
|
7 |
|
@@ -9,14 +9,14 @@ from sentence_transformers import SentenceTransformer, util
|
|
9 |
# ---===--- instances ---===---
|
10 |
embedder = SentenceTransformer('paraphrase-multilingual-mpnet-base-v2')
|
11 |
lex = LexRank()
|
12 |
-
lex_distiluse_v1 =
|
13 |
lex_l12 = LexRankL12()
|
14 |
|
15 |
|
16 |
# 摘要方法1
|
17 |
-
def extract_handler(content):
|
18 |
summary_length = math.ceil(len(content) / 10)
|
19 |
-
sentences = lex.find_central(content)
|
20 |
output = ""
|
21 |
for index, sentence in enumerate(sentences):
|
22 |
output += f"{index}: {sentence}\n"
|
@@ -24,9 +24,9 @@ def extract_handler(content):
|
|
24 |
|
25 |
|
26 |
# 摘要方法2
|
27 |
-
def extract_handler_distiluse_v1(content):
|
28 |
summary_length = math.ceil(len(content) / 10)
|
29 |
-
sentences = lex_distiluse_v1.find_central(content)
|
30 |
output = ""
|
31 |
for index, sentence in enumerate(sentences):
|
32 |
output += f"{index}: {sentence}\n"
|
@@ -34,9 +34,9 @@ def extract_handler_distiluse_v1(content):
|
|
34 |
|
35 |
|
36 |
# 摘要方法3
|
37 |
-
def extract_handler_l12(content):
|
38 |
summary_length = math.ceil(len(content) / 10)
|
39 |
-
sentences = lex_l12.find_central(content)
|
40 |
output = ""
|
41 |
for index, sentence in enumerate(sentences):
|
42 |
output += f"{index}: {sentence}\n"
|
@@ -69,16 +69,25 @@ with gr.Blocks() as app:
|
|
69 |
gr.Markdown("从下面的标签选择测试模块 [摘要生成,相似度检测]")
|
70 |
with gr.Tab("LexRank-mpnet"):
|
71 |
text_input_1 = gr.Textbox(label="请输入长文本:", lines=10, max_lines=1000)
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
text_input_2 = gr.Textbox(label="请输入长文本:", lines=10, max_lines=1000)
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
78 |
with gr.Tab("LexRank-MiniLM-L12-v2"):
|
79 |
text_input_3 = gr.Textbox(label="请输入长文本:", lines=10, max_lines=1000)
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
82 |
with gr.Tab("相似度检测"):
|
83 |
with gr.Row():
|
84 |
text_input_query = gr.Textbox(lines=10, label="查询文本")
|
@@ -86,9 +95,9 @@ with gr.Blocks() as app:
|
|
86 |
text_button_similarity = gr.Button("对比相似度")
|
87 |
text_output_similarity = gr.Textbox()
|
88 |
|
89 |
-
text_button_1.click(extract_handler, inputs=text_input_1, outputs=text_output_1)
|
90 |
-
text_button_2.click(extract_handler_distiluse_v1, inputs=text_input_2, outputs=text_output_2)
|
91 |
-
text_button_3.click(extract_handler_l12, inputs=text_input_3, outputs=text_output_3)
|
92 |
text_button_similarity.click(similarity_search, inputs=[text_input_query, text_input_doc], outputs=text_output_similarity)
|
93 |
|
94 |
app.launch(
|
|
|
1 |
import math, torch, gradio as gr
|
2 |
|
3 |
from lex_rank import LexRank
|
4 |
+
from lex_rank_text2vec_v1 import LexRankText2VecV1
|
5 |
from lex_rank_L12 import LexRankL12
|
6 |
from sentence_transformers import SentenceTransformer, util
|
7 |
|
|
|
9 |
# ---===--- instances ---===---
|
10 |
embedder = SentenceTransformer('paraphrase-multilingual-mpnet-base-v2')
|
11 |
lex = LexRank()
|
12 |
+
lex_distiluse_v1 = LexRankText2VecV1()
|
13 |
lex_l12 = LexRankL12()
|
14 |
|
15 |
|
16 |
# 摘要方法1
|
17 |
+
def extract_handler(content, siblings, num):
|
18 |
summary_length = math.ceil(len(content) / 10)
|
19 |
+
sentences = lex.find_central(content, siblings=siblings, num=num)
|
20 |
output = ""
|
21 |
for index, sentence in enumerate(sentences):
|
22 |
output += f"{index}: {sentence}\n"
|
|
|
24 |
|
25 |
|
26 |
# 摘要方法2
|
27 |
+
def extract_handler_distiluse_v1(content, siblings, num):
|
28 |
summary_length = math.ceil(len(content) / 10)
|
29 |
+
sentences = lex_distiluse_v1.find_central(content, siblings=siblings, num=num)
|
30 |
output = ""
|
31 |
for index, sentence in enumerate(sentences):
|
32 |
output += f"{index}: {sentence}\n"
|
|
|
34 |
|
35 |
|
36 |
# 摘要方法3
|
37 |
+
def extract_handler_l12(content, siblings, num):
|
38 |
summary_length = math.ceil(len(content) / 10)
|
39 |
+
sentences = lex_l12.find_central(content, siblings=siblings, num=num)
|
40 |
output = ""
|
41 |
for index, sentence in enumerate(sentences):
|
42 |
output += f"{index}: {sentence}\n"
|
|
|
69 |
gr.Markdown("从下面的标签选择测试模块 [摘要生成,相似度检测]")
|
70 |
with gr.Tab("LexRank-mpnet"):
|
71 |
text_input_1 = gr.Textbox(label="请输入长文本:", lines=10, max_lines=1000)
|
72 |
+
with gr.Row():
|
73 |
+
text_button_1 = gr.Button("生成摘要")
|
74 |
+
siblings_input_1 = gr.Textbox("请输入摘要的宽度半径, 默认为0, 即显示摘要本身.")
|
75 |
+
num_input_1 = gr.Textbox("摘要的条数, 默认10条")
|
76 |
+
text_output_1 = gr.Textbox(label="摘要文本", lines=10)
|
77 |
+
with gr.Tab("shibing624/text2vec-base-chinese-paraphrase"):
|
78 |
text_input_2 = gr.Textbox(label="请输入长文本:", lines=10, max_lines=1000)
|
79 |
+
with gr.Row():
|
80 |
+
text_button_2 = gr.Button("生成摘要")
|
81 |
+
siblings_input_2 = gr.Textbox("请输入摘要的宽度半径, 默认为0, 即显示摘要本身.")
|
82 |
+
num_input_2 = gr.Textbox("摘要的条数, 默认10条")
|
83 |
+
text_output_2 = gr.Textbox(label="摘要文本", lines=10)
|
84 |
with gr.Tab("LexRank-MiniLM-L12-v2"):
|
85 |
text_input_3 = gr.Textbox(label="请输入长文本:", lines=10, max_lines=1000)
|
86 |
+
with gr.Row():
|
87 |
+
text_button_3 = gr.Button("生成摘要")
|
88 |
+
siblings_input_3 = gr.Textbox("请输入摘要的宽度半径, 默认为0, 即显示摘要本身.")
|
89 |
+
num_input_3 = gr.Textbox("摘要的条数, 默认10条")
|
90 |
+
text_output_3 = gr.Textbox(label="摘要文本", lines=10)
|
91 |
with gr.Tab("相似度检测"):
|
92 |
with gr.Row():
|
93 |
text_input_query = gr.Textbox(lines=10, label="查询文本")
|
|
|
95 |
text_button_similarity = gr.Button("对比相似度")
|
96 |
text_output_similarity = gr.Textbox()
|
97 |
|
98 |
+
text_button_1.click(extract_handler, inputs=[text_input_1, siblings_input_1, num_input_1], outputs=text_output_1)
|
99 |
+
text_button_2.click(extract_handler_distiluse_v1, inputs=[text_input_2, siblings_input_2, num_input_2], outputs=text_output_2)
|
100 |
+
text_button_3.click(extract_handler_l12, inputs=[text_input_3, siblings_input_3, num_input_3], outputs=text_output_3)
|
101 |
text_button_similarity.click(similarity_search, inputs=[text_input_query, text_input_doc], outputs=text_output_similarity)
|
102 |
|
103 |
app.launch(
|