app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Path to our model on Hugging Face Hub
|
| 5 |
+
model_path = "umaru97/gpt2-product-review-generation"
|
| 6 |
+
|
| 7 |
+
# Load model from hub and create a text-generation pipeline
|
| 8 |
+
get_completion = pipeline("text-generation", model=model_path)
|
| 9 |
+
|
| 10 |
+
def text_generation(input):
|
| 11 |
+
output = get_completion(input)
|
| 12 |
+
return output[0]['generated_text']
|
| 13 |
+
|
| 14 |
+
gr.close_all()
|
| 15 |
+
demo = gr.Interface(fn=text_generation,
|
| 16 |
+
inputs=[gr.Textbox(label="Text to start", lines=1)],
|
| 17 |
+
outputs=[gr.Textbox(label="Result", lines=3)],
|
| 18 |
+
title="Text generation with GPT-2",
|
| 19 |
+
description="This demo would generate TV and tablet product reviews.",
|
| 20 |
+
examples=['The TV', 'The tablet']
|
| 21 |
+
)
|
| 22 |
+
demo.launch()
|