Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,23 +4,26 @@ from PIL import Image
|
|
| 4 |
|
| 5 |
# Creates a brief description of a picture using a smart model
|
| 6 |
def generate_caption(image):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
return caption
|
| 11 |
|
| 12 |
# Builds a story from the picture’s description
|
| 13 |
def generate_story(caption):
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
return story
|
| 18 |
|
| 19 |
# Turns the story into spoken audio
|
| 20 |
def generate_audio(story):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
return audio
|
| 25 |
|
| 26 |
# Streamlit UI: Makes a simple interface for kids to enjoy stories
|
|
|
|
| 4 |
|
| 5 |
# Creates a brief description of a picture using a smart model
|
| 6 |
def generate_caption(image):
|
| 7 |
+
with st.spinner("🔍 Looking at your picture..."):
|
| 8 |
+
# Loads the BLIP model to examine and describe the picture
|
| 9 |
+
image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 10 |
+
caption = image_to_text(image)[0]["generated_text"]
|
| 11 |
return caption
|
| 12 |
|
| 13 |
# Builds a story from the picture’s description
|
| 14 |
def generate_story(caption):
|
| 15 |
+
with st.spinner("✍️ Writing a fun story..."):
|
| 16 |
+
# Uses a story model to craft a tale from the description
|
| 17 |
+
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 18 |
+
story = pipe(caption)[0]['generated_text']
|
| 19 |
return story
|
| 20 |
|
| 21 |
# Turns the story into spoken audio
|
| 22 |
def generate_audio(story):
|
| 23 |
+
with st.spinner("🎙️ Turning story into audio..."):
|
| 24 |
+
# Uses a speech model to read the story aloud
|
| 25 |
+
pipe = pipeline("text-to-speech", model="facebook/mms-tts-eng")
|
| 26 |
+
audio = pipe(story)
|
| 27 |
return audio
|
| 28 |
|
| 29 |
# Streamlit UI: Makes a simple interface for kids to enjoy stories
|