File size: 2,406 Bytes
58f448b
ea2c09f
58f448b
 
 
 
 
 
 
 
 
 
 
 
 
ea2c09f
58f448b
 
 
 
 
 
 
 
 
ea2c09f
58f448b
 
 
 
 
 
ea2c09f
 
58f448b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
import streamlit as st
from utils import img2txt, txt2story, txt2speech, get_user_preferences

def main():
    st.set_page_config(page_title="🎨 Image-to-Audio Story 🎧", page_icon="πŸ–ΌοΈ")
    st.title("Turn the Image into Audio Story")

    uploaded_file = st.file_uploader("# πŸ“· Upload an image...", type=["jpg", "jpeg", "png"])

    st.sidebar.markdown("# LLM Inference Configuration Parameters")
    top_k = st.sidebar.number_input("Top-K", min_value=1, max_value=100, value=5)
    top_p = st.sidebar.number_input("Top-P", min_value=0.0, max_value=1.0, value=0.8)
    temperature = st.sidebar.number_input("Temperature", min_value=0.1, max_value=2.0, value=1.5)

    st.markdown("## Story Preferences")
    preferences = get_user_preferences(st)

    if uploaded_file is not None:
        bytes_data = uploaded_file.read()
        with open("uploaded_image.jpg", "wb") as file:
            file.write(bytes_data)

        st.image(uploaded_file, caption='πŸ–ΌοΈ Uploaded Image', use_column_width=True)

        with st.spinner("## πŸ€– AI is at Work! "):
            scenario = img2txt("uploaded_image.jpg")
            
            prompt = f"Based on the image description: '{scenario}', create a {preferences['genre']} story set in {preferences['setting']} in {preferences['continent']}. " \
                     f"The story should have a {preferences['tone']} tone and explore the theme of {preferences['theme']}. " \
                     f"The main conflict should be {preferences['conflict']}. " \
                     f"The story should have a {preferences['twist']} and end with a {preferences['ending']} ending."
            
            story = txt2story(prompt, top_k, top_p, temperature)
            txt2speech(story)

            st.markdown("---")
            st.markdown("## πŸ“œ Image Caption")
            st.write(scenario)

            st.markdown("---")
            st.markdown("## πŸ“– Story")
            st.write(story)

            st.markdown("---")
            st.markdown("## 🎧 Audio Story")
            st.audio("audio_story.mp3")

if __name__ == '__main__':
    main()

# Credits
st.markdown("### Credits")
st.caption('''
            Made with ❀️ by @Aditya-Neural-Net-Ninja\n 
            Utilizes Image-to-Text, Text Generation, Text-to-Speech Transformer Models\n
            Gratitude to Streamlit, πŸ€— Spaces for Deployment & Hosting
            ''')