Update app.py
Browse files
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=
|
17 |
-
return txt
|
18 |
|
19 |
iface = gr.Interface(
|
20 |
fn=poem,
|
21 |
-
inputs=
|
|
|
|
|
|
|
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()
|