import streamlit as st
from transformers import pipeline
from function import img2text, text2story, text2audio
import os
st.set_page_config(
page_title="🦜 Story Maker for Kids",
page_icon="🧒",
layout="centered"
)
# title
st.markdown("
🎨 Picture to Story 🎤
", unsafe_allow_html=True)
st.markdown("Upload your picture and hear a magical story! 🧚
", unsafe_allow_html=True)
# upload picture
uploaded_file = st.file_uploader("📸 Choose a picture of your drawing, pet, or toy!", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
temp_path = os.path.join("/tmp", uploaded_file.name)
with open(temp_path, "wb") as f:
f.write(uploaded_file.getvalue())
st.image(temp_path, caption="Nice Picture! 🎉", use_container_width=True)
with st.spinner("🔍 Thinking about your picture..."):
scenario = img2text(temp_path)
st.markdown("🧠 **What's in the picture?**")
st.markdown(f"> {scenario}")
with st.spinner("✏️ Writing a fun story..."):
story = text2story(scenario)
st.markdown("📖 **Here's your story!**")
st.markdown(f"> {story}")
with st.spinner("🔊 Turning story into voice..."):
audio_file = text2audio(story)
if audio_file:
st.success("✨ All done! Here's your magical story!")
st.markdown("▶️ **Click the play button below to listen!**")
st.audio(audio_file, format="audio/wav")
# bottom
st.markdown("""
Made with 💖 for kids age 3–10
""", unsafe_allow_html=True)