File size: 791 Bytes
9c35959 ba30624 |
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 |
import gradio as gr
from transformers import pipeline
# Load the model from Hugging Face
model = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator")
# Define a function to generate the story
def generate_story(prompt):
result = model(prompt, max_length=100, num_return_sequences=1)
return result[0]['generated_text']
# Define Gradio interface
description = "Story generation with GPT-2"
title = "Generate your own story"
examples = [["Adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
interface = gr.Interface(
fn=generate_story,
inputs=gr.Textbox(lines=2, placeholder="Enter your story prompt here..."),
outputs="text",
description=description,
title=title,
examples=examples
)
interface.launch()
|