File size: 1,043 Bytes
cc2a30b
 
 
 
 
 
 
 
 
8968cf4
 
 
 
 
 
 
cc2a30b
9310cb3
cc2a30b
 
 
 
 
 
 
8268491
8968cf4
cc2a30b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from transformers import pipeline
model1 = pipeline("text-generation",model="uer/gpt2-chinese-poem")

from opencc import OpenCC
t2s=OpenCC('t2s').convert
s2t=OpenCC('s2t').convert

import jiagu

def poem_generator(txt,n=100):
 model_input=t2s(txt)
 poem=model1(model_input, max_length=n)[0]['generated_text']
 poem="".join(poem.split())
 sentiment = jiagu.sentiment(poem)
 return s2t(poem),sentiment[0]

import gradio as gr
inp1=gr.inputs.Textbox(label="่ซ‹่ผธๅ…ฅไธ€ๆฎตๆ–‡ๅญ—")
inp2=gr.inputs.Slider(minimum=50,maximum=250,step=5,default=150, label="็”Ÿๆˆ่ฉฉ่ฉž้•ทๅบฆ")
op1=gr.outputs.Textbox(label="็”Ÿๆˆ่ฉฉ่ฉž็ตๆžœ")
op2=gr.outputs.Textbox(label="ๆƒ…ๆ„Ÿๅˆ†ๆž(positive=ๅๆญฃ้ข, negative=ๅ่ฒ ้ข)")

iface=gr.Interface(fn=poem_generator,
                   inputs=[inp1,inp2],
                   outputs=[op1,op2],
                   title="็น้ซ”ไธญๆ–‡่ฉฉ่ฉž็”Ÿๆˆๅ™จ",
                   description="่ซ‹่ผธๅ…ฅไธ€ๆฎตๆ–‡ๅญ—๏ผŒๆˆ‘ๆœƒๅนซไฝ ็นผ็บŒ็”Ÿๆˆ่ฉฉ่ฉž๏ผŒ้‚„ๆœƒๅนซไฝ ๅˆ†ๆž้€™ๆ•ดๆฎต่ฉฉ่ฉžๆ˜ฏๅๆญฃ้ขๆˆ–่ฒ ้ขๅ–”!")
iface.launch()