Spaces:
Sleeping
Sleeping
File size: 698 Bytes
02ddd69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import gradio as gr
from transformers import pipeline
# Load the story generation pipeline
generator = pipeline("text-generation", model="gpt2", max_length=200)
def generate_story(moral):
prompt = f"The moral of the story is: {moral}. Here's the story:"
story = generator(prompt, max_length=200, num_return_sequences=1)[0]['generated_text']
return story
# Create a Gradio interface
iface = gr.Interface(
fn=generate_story,
inputs=gr.Textbox(label="Enter the moral of the story"),
outputs=gr.Textbox(label="Generated Story"),
title="Moral to Story Generator",
description="Input a moral, and this app will generate a story based on it using AI."
)
iface.launch()
|