Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,17 @@
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
# Import libraries
|
3 |
import gradio as gr
|
4 |
-
import
|
5 |
from gtts import gTTS
|
6 |
from io import BytesIO
|
7 |
from IPython.display import Audio
|
8 |
|
9 |
-
#
|
|
|
10 |
|
11 |
# Set the context for the storyteller
|
12 |
messages = [{"role": "system", "content": "You are a magical storyteller, creating wonderful tales for kids. Make them imaginative and full of joy!"}]
|
@@ -14,12 +19,10 @@ messages = [{"role": "system", "content": "You are a magical storyteller, creati
|
|
14 |
# Define the Storyteller function
|
15 |
def StorytellerGPT(tell_story):
|
16 |
messages.append({"role": "user", "content": tell_story})
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
)
|
22 |
-
story_reply = response["choices"][0]["message"]["content"]
|
23 |
messages.append({"role": "assistant", "content": story_reply})
|
24 |
|
25 |
# Convert text to speech
|
@@ -39,4 +42,5 @@ demo = gr.Interface(
|
|
39 |
description="A magical storyteller app for kids! Type a sentence, and let the app create an enchanting story for you."
|
40 |
)
|
41 |
|
42 |
-
# Launch the Gradio
|
|
|
|
1 |
+
# Install necessary libraries
|
2 |
+
!pip install -q gradio
|
3 |
+
!pip install -q transformers
|
4 |
+
!pip install -q gtts
|
5 |
|
6 |
# Import libraries
|
7 |
import gradio as gr
|
8 |
+
from transformers import pipeline
|
9 |
from gtts import gTTS
|
10 |
from io import BytesIO
|
11 |
from IPython.display import Audio
|
12 |
|
13 |
+
# Create a text generation pipeline with GPT-2
|
14 |
+
story_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
|
15 |
|
16 |
# Set the context for the storyteller
|
17 |
messages = [{"role": "system", "content": "You are a magical storyteller, creating wonderful tales for kids. Make them imaginative and full of joy!"}]
|
|
|
19 |
# Define the Storyteller function
|
20 |
def StorytellerGPT(tell_story):
|
21 |
messages.append({"role": "user", "content": tell_story})
|
22 |
+
|
23 |
+
# Generate story using Hugging Face's GPT-2
|
24 |
+
story_reply = story_generator(tell_story, max_length=100, num_return_sequences=1)[0]['generated_text']
|
25 |
+
|
|
|
|
|
26 |
messages.append({"role": "assistant", "content": story_reply})
|
27 |
|
28 |
# Convert text to speech
|
|
|
42 |
description="A magical storyteller app for kids! Type a sentence, and let the app create an enchanting story for you."
|
43 |
)
|
44 |
|
45 |
+
# Launch the Gradio Interface
|
46 |
+
demo.launch()
|