zuozuo commited on
Commit
49ba46b
·
1 Parent(s): 7d94a8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -12,12 +12,15 @@ tokenizer = BertTokenizer.from_pretrained(".")
12
  model = TFGPT2LMHeadModel.from_pretrained(".")
13
  text_generator = TextGenerationPipeline(model, tokenizer)
14
 
15
- def poem(cls):
16
- txt = text_generator('[CLS]'+cls, max_length=100, do_sample=True)
17
- return txt
18
 
19
  iface = gr.Interface(
20
  fn=poem,
21
- inputs=gr.Textbox(lines=1, placeholder="春眠不觉晓,"),
 
 
 
22
  outputs="text")
23
  iface.launch()
 
12
  model = TFGPT2LMHeadModel.from_pretrained(".")
13
  text_generator = TextGenerationPipeline(model, tokenizer)
14
 
15
+ def poem(cls,max_length):
16
+ txt = text_generator('[CLS]'+cls, max_length=int(max_length), do_sample=True)
17
+ return txt[0]['generated_text'].replace('[CLS]','').replace('[SEP]','').replace(' ','')
18
 
19
  iface = gr.Interface(
20
  fn=poem,
21
+ inputs=[
22
+ gr.Textbox(lines=1, default="春眠不觉晓,",label="请输入一句诗词:"),
23
+ gr.Number(50,label='字数:',default=50),
24
+ ],
25
  outputs="text")
26
  iface.launch()