File size: 922 Bytes
41312c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

from transformers import GPT2Tokenizer, TFGPT2LMHeadModel, pipeline
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = TFGPT2LMHeadModel.from_pretrained('gpt2')

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)


def predict(x):
    output = pipe(text_inputs=x, max_length=50)
    return output[0]['generated_text']


with gr.Blocks() as demo:
    gr.Markdown("# Generate some text with this demo ! ")
    input = gr.Textbox(label="Input Text")
    output = gr.Textbox(label="Output Text")
    generate_btn = gr.Button("Generate")
    generate_btn.click(fn=predict, inputs=input, outputs=output)
    gr.Markdown("## Examples")
    gr.Examples(examples=["My name is James and i like", "I go every day at the "],
                cache_examples=True,
                inputs=input,
                outputs=output,
                fn=predict)


demo.launch(server_name="0.0.0.0")