alexyuyxj's picture
Update app.py
70e7ec8
raw
history blame
996 Bytes
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()