File size: 1,095 Bytes
f8df04e
 
c5114dd
f8df04e
c5114dd
 
f8df04e
 
 
 
 
 
 
c5114dd
 
 
 
f8df04e
 
7cd6d1f
f8df04e
 
 
 
 
7cd6d1f
f8df04e
 
 
 
c5114dd
5ce8815
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
28
29
30
31
32
33
# Import libraries
import gradio as gr
from transformers import pipeline

# Create a text generation pipeline with GPT-2
story_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")

# Set the context for the storyteller
messages = [{"role": "system", "content": "You are a magical storyteller, creating wonderful tales for kids. Make them imaginative and full of joy!"}]

# Define the Storyteller function
def StorytellerGPT(tell_story):
    messages.append({"role": "user", "content": tell_story})
    
    # Generate story using Hugging Face's GPT-2
    story_reply = story_generator(tell_story, max_length=100, num_return_sequences=1)[0]['generated_text']
    
    messages.append({"role": "assistant", "content": story_reply})

    return story_reply

# Create the Gradio Interface
demo = gr.Interface(
    fn=StorytellerGPT,
    inputs="text",
    outputs="text",
    title="πŸ“– Storytelling Magic",
    description="A magical storyteller app for kids! Type a sentence, and let the app create an enchanting story for you."
)

# Launch the Gradio Interface
demo.launch()