File size: 807 Bytes
89be4e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import pipeline
import gradio as gr

# Path to our model on Hugging Face Hub
model_path = "umaru97/gpt2-product-review-generation"

# Load model from hub and create a text-generation pipeline
get_completion = pipeline("text-generation", model=model_path)

def text_generation(input):
    output = get_completion(input)
    return output[0]['generated_text']

gr.close_all()
demo = gr.Interface(fn=text_generation,
                    inputs=[gr.Textbox(label="Text to start", lines=1)],
                    outputs=[gr.Textbox(label="Result", lines=3)],
                    title="Text generation with GPT-2",
                    description="This demo would generate TV and tablet product reviews.",
                    examples=['The TV', 'The tablet']
                   )
demo.launch()