File size: 1,686 Bytes
769189f
 
94512ab
6ea94ad
769189f
94512ab
 
 
 
 
769189f
3807689
94512ab
 
 
3807689
94512ab
769189f
 
6ea94ad
 
 
 
 
94512ab
 
fe6d5e4
94512ab
 
 
 
 
 
 
 
 
 
 
fe6d5e4
 
 
769189f
94512ab
3807689
94512ab
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)