File size: 1,113 Bytes
bed8885 9d1d724 bed8885 43dd320 7d94a8b 9d1d724 bed8885 f533b89 2e97ecd 49ba46b 2e97ecd bed8885 9d1d724 49ba46b f533b89 9d7e6df 49ba46b f533b89 2e97ecd bed8885 |
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 29 30 31 32 33 |
'''
Author: zuojianghua
Date: 2022-07-06 10:40:08
LastEditTime: 2022-07-07 17:03:34
LastEditors: zuojianghua
Description:
FilePath: /zuo/app.py
'''
import gradio as gr
from transformers import BertTokenizer, TFGPT2LMHeadModel,TextGenerationPipeline
tokenizer = BertTokenizer.from_pretrained(".")
model = TFGPT2LMHeadModel.from_pretrained(".")
text_generator = TextGenerationPipeline(model, tokenizer)
title = "写一首诗"
article = "<div style='text-align: center;'>使用的模型:<a href='https://huggingface.co/uer/gpt2-chinese-poem' target='_blank'>https://huggingface.co/uer/gpt2-chinese-poem</a></div>"
def poem(cls, max_length):
txt = text_generator('[CLS]'+cls, max_length=int(max_length), do_sample=True)
return txt[0]['generated_text'].replace('[CLS]','').replace('[SEP]','').replace(' ','').replace('。','。\n')
iface = gr.Interface(
fn=poem,
inputs=[
gr.Textbox("今晚提测又加班,BUG一堆改不完。", lines=1, label="请输入第一句:"),
gr.Number(66, label='字数:'),
],
outputs=gr.Textbox(lines=6),
title=title,
article=article)
iface.launch() |