assignment3 / app.py
leoxia711's picture
Update app.py
3807689 verified
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("<h1 style='text-align: center; color: #FF69B4;'>🎨 Picture to Story 🎀</h1>", unsafe_allow_html=True)
st.markdown("<h3 style='text-align: center;'>Upload your picture and hear a magical story! 🧚</h3>", 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("""
<hr>
<p style='text-align:center; color: grey; font-size: 0.9em'>
Made with πŸ’– for kids age 3–10
</p>
""", unsafe_allow_html=True)