alexyuyxj commited on
Commit
666f5de
1 Parent(s): 15e9c71

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ translator = pipeline("translation", model = "penpen/novel-zh-en", max_time = 7)
5
+ classifier = pipeline ("text-classification", model = 'bhadresh-savani/bert-base-uncased-emotion', top_k = 1)
6
+
7
+ def on_click(chines_text):
8
+ text = translator(chines_text)[0]["translation_text"]
9
+ return text, classifier(text)
10
+
11
+ with gr.Blocks() as block:
12
+ gr.Markdown("<center><h1>中文情感识别</h1></center>")
13
+ tb_input = gr.Textbox(label = "输入", placeholder = "输入中文句子", lines = 1)
14
+ btn = gr.Button("识别", variant = 'primary')
15
+ tb_tans = gr.Textbox(label = "翻译结果")
16
+ tb_class = gr.Textbox(label = "识别结果")
17
+ btn.click(fn = on_click, inputs = tb_input, outputs = [tb_tans, tb_class])
18
+ block.queue(concurrency_count = 30)
19
+ block.launch()