mayf commited on
Commit
504dc12
·
verified ·
1 Parent(s): 8367fb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import streamlit as st
2
  from PIL import Image
3
  from transformers import pipeline
@@ -11,9 +13,9 @@ st.title("🖼️ ➡️ 📖 Interactive Storyteller")
11
  # —––––––– Cache model loading
12
  @st.cache_resource
13
  def load_pipelines():
14
- # 1) Image captioning
15
  captioner = pipeline(
16
- "image-captioning",
17
  model="Salesforce/blip-image-captioning-base"
18
  )
19
  # 2) Story generation with Flan-T5
@@ -33,7 +35,9 @@ if uploaded:
33
 
34
  # —––––––– 1. Caption
35
  with st.spinner("🔍 Looking at the image..."):
36
- cap = captioner(image)[0]["generated_text"]
 
 
37
  st.markdown(f"**Caption:** {cap}")
38
 
39
  # —––––––– 2. Story generation
@@ -60,4 +64,4 @@ if uploaded:
60
  tmp = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False)
61
  tts.write_to_fp(tmp)
62
  tmp.flush()
63
- st.audio(tmp.name, format="audio/mp3")
 
1
+ # app.py
2
+
3
  import streamlit as st
4
  from PIL import Image
5
  from transformers import pipeline
 
13
  # —––––––– Cache model loading
14
  @st.cache_resource
15
  def load_pipelines():
16
+ # 1) Image-to-text (captioning)
17
  captioner = pipeline(
18
+ "image-to-text",
19
  model="Salesforce/blip-image-captioning-base"
20
  )
21
  # 2) Story generation with Flan-T5
 
35
 
36
  # —––––––– 1. Caption
37
  with st.spinner("🔍 Looking at the image..."):
38
+ cap_outputs = captioner(image)
39
+ # BLIP returns a list of dicts with key "generated_text"
40
+ cap = cap_outputs[0].get("generated_text", "").strip()
41
  st.markdown(f"**Caption:** {cap}")
42
 
43
  # —––––––– 2. Story generation
 
64
  tmp = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False)
65
  tts.write_to_fp(tmp)
66
  tmp.flush()
67
+ st.audio(tmp.name, format="audio/mp3")