File size: 996 Bytes
666f5de
 
 
 
 
 
 
adf1507
87d6d9f
adf1507
87d6d9f
adf1507
 
 
666f5de
 
 
 
adf1507
666f5de
 
 
 
70e7ec8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import pipeline
import gradio as gr

translator = pipeline("translation", model = "penpen/novel-zh-en", max_time = 7)
classifier = pipeline ("text-classification", model = 'bhadresh-savani/bert-base-uncased-emotion', top_k = 1)

def on_click(chines_text):
    print('input: ', chines_text)
    text = translator(chines_text)[0]["translation_text"]
    print('translate: ', text)
    result = text, classifier(text)
    print('classify: ', result)
    print('----------------------------')
    return result

with gr.Blocks() as block:
    gr.Markdown("<center><h1>中文情感识别</h1></center>")
    tb_input = gr.Textbox(label = "输入", placeholder = "输入中文句子", lines = 1)
    btn = gr.Button("翻译并识别", variant = 'primary')
    tb_tans = gr.Textbox(label = "翻译结果")
    tb_class = gr.Textbox(label = "识别结果")
    btn.click(fn = on_click, inputs = tb_input, outputs = [tb_tans, tb_class])
block.queue(concurrency_count = 30)
block.launch()