|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
model = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator") |
|
|
|
|
|
|
|
|
def generate_story(prompt): |
|
|
result = model(prompt, max_length=100, num_return_sequences=1) |
|
|
return result[0]['generated_text'] |
|
|
|
|
|
|
|
|
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() |
|
|
|