Spaces:
Sleeping
Sleeping
Delet app.py
Browse files
app.py
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import openai
|
3 |
-
import whisper
|
4 |
-
from PIL import Image
|
5 |
-
from diffusers import StableDiffusionPipeline
|
6 |
-
|
7 |
-
# Set your OpenAI API key
|
8 |
-
openai.api_key = ""
|
9 |
-
|
10 |
-
# Initialize text generation and image generation pipelines
|
11 |
-
text_generation_pipe = openai.Completion.create
|
12 |
-
image_generation_pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
13 |
-
|
14 |
-
# Initialize Whisper API key for text-to-speech
|
15 |
-
whisper_api_key = ""
|
16 |
-
|
17 |
-
# Define function for generating stories and illustrations
|
18 |
-
def generate_story_and_illustration(prompt, character_name):
|
19 |
-
# Generate story
|
20 |
-
story_text = text_generation_pipe(engine="text-davinci-003", prompt=f"Once upon a time, {character_name}... {prompt}", max_tokens=150)["choices"][0]["text"]
|
21 |
-
|
22 |
-
# Generate image based on story
|
23 |
-
image = image_generation_pipe(story_text)
|
24 |
-
|
25 |
-
# Convert story text to speech using Whisper API
|
26 |
-
tts_result = whisper.transcribe(audio="content.flac", language="en", api_key=whisper_api_key)
|
27 |
-
audio_data = tts_result["segments"][0]["alternatives"][0]["text"]
|
28 |
-
|
29 |
-
# Return story text, audio data, and image
|
30 |
-
return story_text, audio_data, image.images[0]
|
31 |
-
|
32 |
-
# Create Gradio interface
|
33 |
-
interface = gr.Interface(
|
34 |
-
fn=generate_story_and_illustration,
|
35 |
-
inputs=[
|
36 |
-
gr.Textbox(label="Start your story with..."),
|
37 |
-
gr.Textbox(label="Give your character a name:"),
|
38 |
-
],
|
39 |
-
outputs=[
|
40 |
-
gr.Textbox(label="Story"),
|
41 |
-
gr.Audio(label="Listen to the story"),
|
42 |
-
gr.Image(label="See the story come alive"),
|
43 |
-
],
|
44 |
-
title="Storyteller Playground",
|
45 |
-
description="Create amazing stories with the help of AI!",
|
46 |
-
theme="kids",
|
47 |
-
)
|
48 |
-
|
49 |
-
# Launch the app on Hugging Face Spaces
|
50 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|