GH111 commited on
Commit
d921720
·
1 Parent(s): d9b5fef

Delet app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -55
app.py DELETED
@@ -1,55 +0,0 @@
1
- # Import libraries
2
- import gradio as gr
3
- from transformers import pipeline
4
- from gtts import gTTS
5
- from io import BytesIO
6
- from PIL import Image
7
-
8
- # Create a text generation pipeline with GPT-2
9
- story_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
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!"}]
13
-
14
- # Define the Storyteller function
15
- def StorytellerGPT(character, child_name, lesson_choice, tell_story):
16
- # Set the characters and lesson based on user choices
17
- character_info = f"Once upon a time, {child_name} met {character}. "
18
- lesson_info = f"Today's lesson is about {lesson_choice}. "
19
-
20
- messages.append({"role": "user", "content": tell_story})
21
-
22
- # Generate story using Hugging Face's GPT-2
23
- story_reply = story_generator(character_info + lesson_info + tell_story, max_length=150, num_return_sequences=1)[0]['generated_text']
24
-
25
- messages.append({"role": "assistant", "content": story_reply})
26
-
27
- # Convert text to speech
28
- tts = gTTS(text=story_reply, lang='en', slow=False)
29
- audio_io = BytesIO()
30
- tts.save(audio_io)
31
- audio_io.seek(0)
32
-
33
- # Convert text to image
34
- image = Image.new("RGB", (300, 300), (255, 255, 255))
35
- image_path = "/path/to/output/image.png"
36
- image.save(image_path)
37
-
38
- return story_reply, Audio(data=audio_io.read(), autoplay=True), image
39
-
40
- # Create the Gradio Interface
41
- demo = gr.Interface(
42
- fn=StorytellerGPT,
43
- inputs=[
44
- gr.Textbox("text", label="Child's Name"),
45
- gr.Dropdown(["unicorn", "dragon", "wizard"], label="Choose a Character"),
46
- gr.Dropdown(["kindness", "creativity", "bravery"], label="Choose a Lesson"),
47
- gr.Textbox("text", label="Start the Story with"),
48
- ],
49
- outputs=["text", "audio", "image"],
50
- title="📖 Storytelling Magic",
51
- description="A magical storyteller app for kids! Choose characters, add your name, and select the lesson you want to learn.",
52
- )
53
-
54
- # Launch the Gradio Interface
55
- demo.launch(