File size: 1,705 Bytes
6568454
98ab077
 
6568454
98ab077
6568454
98ab077
 
6568454
98ab077
 
 
6568454
98ab077
 
6568454
98ab077
 
 
 
55c0f00
98ab077
 
6568454
98ab077
 
 
6568454
98ab077
 
6568454
98ab077
 
 
6568454
98ab077
 
 
 
 
 
 
6568454
98ab077
 
 
6568454
 
98ab077
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import openai
import whisper
from PIL import Image
from diffusers import StableDiffusionPipeline

# Set your OpenAI API key
openai.api_key = ""

# Initialize text generation and image generation pipelines
text_generation_pipe = openai.Completion.create
image_generation_pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")

# Initialize Whisper API key for text-to-speech
whisper_api_key = ""

# Define function for generating stories and illustrations
def generate_story_and_illustration(prompt, character_name):
    # Generate story
    story_text = text_generation_pipe(engine="text-davinci-003", prompt=f"Once upon a time, {character_name}... {prompt}", max_tokens=150)["choices"][0]["text"]

    # Generate image based on story
    image = image_generation_pipe(story_text)

    # Convert story text to speech using Whisper API
    tts_result = whisper.transcribe(audio="content.flac", language="en", api_key=whisper_api_key)
    audio_data = tts_result["segments"][0]["alternatives"][0]["text"]

    # Return story text, audio data, and image
    return story_text, audio_data, image.images[0]

# Create Gradio interface
interface = gr.Interface(
    fn=generate_story_and_illustration,
    inputs=[
        gr.Textbox(label="Start your story with..."),
        gr.Textbox(label="Give your character a name:"),
    ],
    outputs=[
        gr.Textbox(label="Story"),
        gr.Audio(label="Listen to the story"),
        gr.Image(label="See the story come alive"),
    ],
    title="Storyteller Playground",
    description="Create amazing stories with the help of AI!",
    theme="kids",
)

# Launch the app on Hugging Face Spaces
interface.launch()