File size: 2,655 Bytes
1d906b4
 
 
eab86f7
1d906b4
 
 
 
 
 
 
 
 
 
 
 
 
eab86f7
1d906b4
 
 
 
 
 
 
24452be
1d906b4
 
eab86f7
 
1d906b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eab86f7
1d906b4
 
 
 
 
 
24452be
1d906b4
 
 
 
 
 
eab86f7
1d906b4
 
 
 
 
 
 
 
 
 
 
 
eab86f7
1d906b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import streamlit as st
from gtts import gTTS

from img_gen import generate_story
from prompt_generation import pipeline


# Function to create the page navigation
def page_navigation(current_page):
    col1, col2, col3 = st.columns(3)

    if current_page > 0:
        with col1:
            if st.button('<< Previous'):
                current_page -= 1

    with col2:
        print(f'Step {current_page} of 10')

    if current_page < 10:
        with col3:
            if st.button('Next >>'):
                if current_page == 0:
                    user_input = st.session_state.user_input
                    prompt_response = pipeline(user_input, 10)
                    image_prompts_steps = prompt_response.get("image_prompts")
                    init_prompt = prompt_response.get("story")

                    init_img, img_dict = generate_story(init_prompt,
                                                        image_prompts_steps)

                    st.session_state.pipeline_response = prompt_response
                    st.session_state.init_img = init_img
                    st.session_state.img_dict = img_dict

                current_page += 1

    return current_page


# Main function to display the pages
def get_pipeline_data(page_number):
    pipeline_response = st.session_state.pipeline_response
    text_output = pipeline_response.get("steps")[page_number - 1]
    img_dict = st.session_state.img_dict
    img = img_dict[page_number - 1].get("image")

    return {"text_output": text_output, "image_obj": img}


def main():
    st.set_page_config(page_title="Narrative chat", layout="wide")
    st.title("DreamGPT")

    # Initialize the current page
    current_page = st.session_state.get('current_page', 0)

    # Display content for each page
    if current_page == 0:
        st.write("Describe a story you would like me to tell:")
        user_input = st.text_area("")
        st.session_state.user_input = user_input

    else:
        # Retrieve data from random generators
        data = get_pipeline_data(current_page)
        text_output = data.get('text_output', '')
        image = data.get('image_obj', '')

        # Display text output
        st.write(text_output)

        tts = gTTS(text_output.split(".", 1)[1])
        tts.save('audio.mp3')
        st.audio('audio.mp3')

        # Display image output
        if image:
            st.image(image, use_column_width=False, width=400)

    # Display page navigation
    current_page = page_navigation(current_page)

    st.write('current_page:', current_page)
    st.session_state.current_page = current_page


if __name__ == "__main__":
    main()