File size: 632 Bytes
bed8885
 
 
9d1d724
bed8885
 
 
 
 
9d1d724
 
 
 
bed8885
9d1d724
 
 
bed8885
9d1d724
 
 
 
bed8885
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
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, GPT2LMHeadModel,TextGenerationPipeline
tokenizer = BertTokenizer.from_pretrained(".")
model = GPT2LMHeadModel.from_pretrained(".")
text_generator = TextGenerationPipeline(model, tokenizer) 

def poem(cls):
    txt = text_generator('[CLS]'+cls, max_length=100, do_sample=True)
    return txt 

iface = gr.Interface(
  fn=poem, 
  inputs=gr.Textbox(lines=1, placeholder="春眠不觉晓,"),
  outputs="text")
iface.launch()