GH111 commited on
Commit
a546c80
·
1 Parent(s): 3df6e74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from gtts import gTTS
4
+ from io import BytesIO
5
+ from PIL import Image
6
+
7
+ # Initialize transformers for each task
8
+ text_generation_pipe = pipeline("text-generation", model="gpt2")
9
+ text_to_speech_pipe = pipeline("text-to-speech", model="google")
10
+ image_generation_pipe = pipeline("image-generation", model="stable-diffusion")
11
+
12
+ # Function for generating stories, audio, and illustrations
13
+ def generate_story_and_illustration(prompt, character_name):
14
+ # Generate story text
15
+ story_text = text_generation_pipe(prompt=f"Once upon a time, {character_name}... {prompt}", max_length=150)[0]["generated_text"]
16
+
17
+ # Generate audio from story text
18
+ tts_audio = gTTS(text=story_text, lang="en")
19
+ audio_buffer = BytesIO()
20
+ tts_audio.save(audio_buffer)
21
+ audio_buffer.seek(0)
22
+
23
+ # Generate image based on story
24
+ image = image_generation_pipe(prompt=story_text)
25
+
26
+ # Return generated story, audio, and image
27
+ return story_text, audio_buffer.read(), image
28
+
29
+ # Gradio interface for user interaction
30
+ interface = gr.Interface(
31
+ fn=generate_story_and_illustration,
32
+ inputs=[
33
+ gr.Textbox(label="Start your story with..."),
34
+ gr.Textbox(label="Give your character a name:"),
35
+ ],
36
+ outputs=[
37
+ gr.Textbox(label="Story"),
38
+ gr.Audio(label="Listen to the story"),
39
+ gr.Image(label="See the story come alive"),
40
+ ],
41
+ title="Storyteller Playground",
42
+ description="Create amazing stories with the help of AI!",
43
+ theme="kids",
44
+ )
45
+
46
+ # Launch the app
47
+ interface.launch()