xusong28
commited on
Commit
•
5b47e63
1
Parent(s):
7faefc8
upgrade gradio to 3.12.0
Browse files- app.py +1 -0
- demo_chatbot_jddc.py +3 -2
- demo_corrector.py +3 -1
- demo_mlm.py +3 -3
- demo_sum.py +3 -4
- gradio_patch.py +10 -0
- info.py +2 -0
app.py
CHANGED
@@ -11,6 +11,7 @@ https://gradio.app/docs/#tabbedinterface-header
|
|
11 |
-
|
12 |
"""
|
13 |
|
|
|
14 |
import gradio as gr
|
15 |
from demo_sum import sum_iface
|
16 |
from demo_mlm import mlm_iface
|
|
|
11 |
-
|
12 |
"""
|
13 |
|
14 |
+
import gradio_patch
|
15 |
import gradio as gr
|
16 |
from demo_sum import sum_iface
|
17 |
from demo_mlm import mlm_iface
|
demo_chatbot_jddc.py
CHANGED
@@ -4,6 +4,7 @@
|
|
4 |
|
5 |
import torch
|
6 |
import gradio as gr
|
|
|
7 |
from kplug import modeling_kplug_s2s_patch
|
8 |
from transformers import BertTokenizer, BartForConditionalGeneration
|
9 |
|
@@ -50,13 +51,13 @@ jddc_iface = gr.Interface(
|
|
50 |
inputs=[
|
51 |
gr.Textbox(
|
52 |
label="输入文本",
|
53 |
-
value="发什么快递"),
|
54 |
"state"
|
55 |
],
|
56 |
outputs=["chatbot", "state"],
|
57 |
-
|
58 |
examples=jddc_examples,
|
59 |
title="电商客服--生成式对话(Response Generation)",
|
|
|
60 |
)
|
61 |
|
62 |
if __name__ == "__main__":
|
|
|
4 |
|
5 |
import torch
|
6 |
import gradio as gr
|
7 |
+
from info import article
|
8 |
from kplug import modeling_kplug_s2s_patch
|
9 |
from transformers import BertTokenizer, BartForConditionalGeneration
|
10 |
|
|
|
51 |
inputs=[
|
52 |
gr.Textbox(
|
53 |
label="输入文本",
|
54 |
+
value="发什么快递"), # gr.State() 报错
|
55 |
"state"
|
56 |
],
|
57 |
outputs=["chatbot", "state"],
|
|
|
58 |
examples=jddc_examples,
|
59 |
title="电商客服--生成式对话(Response Generation)",
|
60 |
+
article=article,
|
61 |
)
|
62 |
|
63 |
if __name__ == "__main__":
|
demo_corrector.py
CHANGED
@@ -5,6 +5,7 @@
|
|
5 |
import time
|
6 |
import torch
|
7 |
import gradio as gr
|
|
|
8 |
from transformers import FillMaskPipeline
|
9 |
from transformers import BertTokenizer
|
10 |
from kplug.modeling_kplug import KplugForMaskedLM
|
@@ -79,7 +80,8 @@ corr_iface = gr.Interface(
|
|
79 |
],
|
80 |
examples=error_sentences,
|
81 |
title="文本纠错(Corrector)",
|
82 |
-
description='自动对汉语文本中的拼写、语法、标点等多种问题进行纠错校对,提示错误位置并返回修改建议'
|
|
|
83 |
)
|
84 |
|
85 |
if __name__ == "__main__":
|
|
|
5 |
import time
|
6 |
import torch
|
7 |
import gradio as gr
|
8 |
+
from info import article
|
9 |
from transformers import FillMaskPipeline
|
10 |
from transformers import BertTokenizer
|
11 |
from kplug.modeling_kplug import KplugForMaskedLM
|
|
|
80 |
],
|
81 |
examples=error_sentences,
|
82 |
title="文本纠错(Corrector)",
|
83 |
+
description='自动对汉语文本中的拼写、语法、标点等多种问题进行纠错校对,提示错误位置并返回修改建议',
|
84 |
+
article=article
|
85 |
)
|
86 |
|
87 |
if __name__ == "__main__":
|
demo_mlm.py
CHANGED
@@ -18,6 +18,7 @@ interface = gr.Interface.load(
|
|
18 |
"""
|
19 |
|
20 |
import gradio as gr
|
|
|
21 |
from transformers import FillMaskPipeline
|
22 |
from transformers import BertTokenizer
|
23 |
from kplug.modeling_kplug import KplugForMaskedLM
|
@@ -50,9 +51,8 @@ mlm_iface = gr.Interface(
|
|
50 |
),
|
51 |
examples=mlm_examples,
|
52 |
title="文本填词(Fill Mask)",
|
53 |
-
description='基于KPLUG
|
54 |
-
|
55 |
-
' and Generation in E-Commerce (Findings of EMNLP 2021) </a>。'
|
56 |
)
|
57 |
|
58 |
if __name__ == "__main__":
|
|
|
18 |
"""
|
19 |
|
20 |
import gradio as gr
|
21 |
+
from info import article
|
22 |
from transformers import FillMaskPipeline
|
23 |
from transformers import BertTokenizer
|
24 |
from kplug.modeling_kplug import KplugForMaskedLM
|
|
|
51 |
),
|
52 |
examples=mlm_examples,
|
53 |
title="文本填词(Fill Mask)",
|
54 |
+
description='基于KPLUG预训练语言模型',
|
55 |
+
article=article
|
|
|
56 |
)
|
57 |
|
58 |
if __name__ == "__main__":
|
demo_sum.py
CHANGED
@@ -12,6 +12,7 @@ promp参数
|
|
12 |
|
13 |
import torch
|
14 |
import gradio as gr
|
|
|
15 |
from kplug import modeling_kplug_s2s_patch
|
16 |
from transformers import BertTokenizer, BartForConditionalGeneration
|
17 |
|
@@ -47,10 +48,8 @@ sum_iface = gr.Interface(
|
|
47 |
),
|
48 |
examples=sum_examples,
|
49 |
title="生成式摘要(Abstractive Summarization)",
|
50 |
-
description='
|
51 |
-
|
52 |
-
'<div><a href="https://aclanthology.org/2021.findings-emnlp.1/">pdf</a> </div>'
|
53 |
-
'<div><a href="https://github.com/xu-song/k-plug">code </a> </div>'
|
54 |
)
|
55 |
|
56 |
if __name__ == "__main__":
|
|
|
12 |
|
13 |
import torch
|
14 |
import gradio as gr
|
15 |
+
from info import article
|
16 |
from kplug import modeling_kplug_s2s_patch
|
17 |
from transformers import BertTokenizer, BartForConditionalGeneration
|
18 |
|
|
|
48 |
),
|
49 |
examples=sum_examples,
|
50 |
title="生成式摘要(Abstractive Summarization)",
|
51 |
+
description='生成式摘要,用于电商领域的商品营销文案写作。输入商品信息,输出商品的营销文案。',
|
52 |
+
article=article
|
|
|
|
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
gradio_patch.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
|
3 |
+
"""
|
4 |
+
huggingface默认gradio版本是3.1.7。在多tab下的chatbot报错。因此需要更新到3.12.0
|
5 |
+
https://www.kingname.info/2019/10/29/pip-in-code/
|
6 |
+
"""
|
7 |
+
|
8 |
+
from pip._internal import main
|
9 |
+
|
10 |
+
main(['install', 'gradio==3.12.0'])
|
info.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
|
2 |
+
article = "<p style='text-align: center'><a href='https://aclanthology.org/2021.findings-emnlp.1/'>K-PLUG: Knowledge-injected Pre-trained Language Model for Natural Language Understanding and Generation in E-Commerce</a> | <a href='https://github.com/xu-song/k-plug'>Github Repo</a></p>"
|