Spaces:
Sleeping
Sleeping
| 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) | |