Lifan-Z's picture
Update app.py
cc6c34c
raw
history blame
927 Bytes
import transformers
import gradio as gr
from transformers import pipeline
gpt2 = pipeline('text-generation', model = "Lifan-Z/Chinese-Classic-Poem-Generator-style7x4-GPT2")
def poems(st):
poems=""
sequences = gpt2('<|endoftext|>'+st, max_length=34, do_sample=True, top_k=20, top_p=0.9, repetition_penalty=1.2, num_return_sequences=20, eos_token_id=0)
i=0
for seq in sequences:
if (len(seq.get('generated_text')) == 76):
poems = poems + (str(seq.get('generated_text'))[13:76]) + "\n\n"
i=i+1
if(i==6):
return(poems)
textbox = gr.Textbox(label="输入0~7个汉字作为诗的开头,以英文空格分隔,末尾不用空格。一次六首,大概10秒。(Enter 0~7 Chinese characters to be the beginning of the poem, separated by a space. )", placeholder="山 明 水 净 夜 来 霜", lines=11)
iface = gr.Interface(fn=poems, inputs=textbox, outputs="text")
iface.launch(share=True)