scmlewis commited on
Commit
1d39cce
·
verified ·
1 Parent(s): f28c5f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
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
- # Loads the BLIP model to examine and describe the picture
8
- image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
9
- caption = image_to_text(image)[0]["generated_text"]
 
10
  return caption
11
 
12
  # Builds a story from the picture’s description
13
  def generate_story(caption):
14
- # Uses a story model to craft a tale from the description
15
- pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
16
- story = pipe(caption)[0]['generated_text']
 
17
  return story
18
 
19
  # Turns the story into spoken audio
20
  def generate_audio(story):
21
- # Uses a speech model to read the story aloud
22
- pipe = pipeline("text-to-speech", model="facebook/mms-tts-eng")
23
- audio = pipe(story)
 
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