GH111 commited on
Commit
7ac2f8c
·
1 Parent(s): 6568454

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -1,9 +1,3 @@
1
- # Install required libraries
2
- !pip install gtts
3
- !pip install gradio
4
- !pip install transformers
5
- !pip install diffusers
6
-
7
  # Import libraries
8
  import gradio as gr
9
  from gtts import gTTS
@@ -13,7 +7,7 @@ from diffusers import DiffusionPipeline
13
  import openai
14
 
15
  # Set your OpenAI API key
16
- openai.api_key = "sk-pZv0gFbHlaKc5o3ejPgYT3BlbkFJ7DPw0d1FqJApeZTBjIqic"
17
 
18
  # Use a DiffusionPipeline for text-to-image
19
  image_generation_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt")
@@ -48,10 +42,11 @@ def StorytellerGPT(character, child_name, lesson_choice, tell_story, _):
48
 
49
  # Convert text to speech using Whisper API
50
  # Replace "YOUR_WHISPER_API_KEY" with your actual Whisper API key
51
- whisper_api_key = "sk-pZv0gFbHlaKc5o3ejPgYT3BlbkFJ7DPw0d1FqJApeZTBjIqic"
52
  tts = gTTS(text=story_reply, lang='en', slow=False, whisper_api_key=whisper_api_key)
53
  audio_io = BytesIO()
54
- tts.save("/content/audio_output.mp3")
 
55
 
56
  # Convert text to image using DiffusionPipeline
57
  image_reply = image_generation_pipe(story_reply)
@@ -60,7 +55,7 @@ def StorytellerGPT(character, child_name, lesson_choice, tell_story, _):
60
  story_pages = story_reply.split("\n\n") # Split the story into pages
61
  current_page = min(current_page, len(story_pages) - 1) # Ensure the current_page is within bounds
62
 
63
- return story_pages[current_page], "/content/audio_output.mp3", image_reply
64
 
65
  # Create the Gradio Interface with styling
66
  demo = gr.Interface(
 
 
 
 
 
 
 
1
  # Import libraries
2
  import gradio as gr
3
  from gtts import gTTS
 
7
  import openai
8
 
9
  # Set your OpenAI API key
10
+ openai.api_key = "YOUR_OPENAI_API_KEY"
11
 
12
  # Use a DiffusionPipeline for text-to-image
13
  image_generation_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt")
 
42
 
43
  # Convert text to speech using Whisper API
44
  # Replace "YOUR_WHISPER_API_KEY" with your actual Whisper API key
45
+ whisper_api_key = "YOUR_WHISPER_API_KEY"
46
  tts = gTTS(text=story_reply, lang='en', slow=False, whisper_api_key=whisper_api_key)
47
  audio_io = BytesIO()
48
+ tts.save(audio_io)
49
+ audio_io.seek(0)
50
 
51
  # Convert text to image using DiffusionPipeline
52
  image_reply = image_generation_pipe(story_reply)
 
55
  story_pages = story_reply.split("\n\n") # Split the story into pages
56
  current_page = min(current_page, len(story_pages) - 1) # Ensure the current_page is within bounds
57
 
58
+ return story_pages[current_page], Audio(data=audio_io.read(), autoplay=True), image_reply
59
 
60
  # Create the Gradio Interface with styling
61
  demo = gr.Interface(