File size: 8,962 Bytes
4a68fe0
 
9ffa7ce
 
4a68fe0
9ffa7ce
4a68fe0
 
 
 
 
3e0a1b1
 
 
4a68fe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ffa7ce
b802421
9ffa7ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1597842
 
4a68fe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e0a1b1
4a68fe0
3e0a1b1
 
 
 
 
 
 
 
 
 
 
9ffa7ce
3e0a1b1
 
 
 
 
 
 
 
 
9ffa7ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e0a1b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a68fe0
 
 
1597842
4a68fe0
 
 
 
 
 
 
 
 
 
 
 
 
 
1597842
 
 
 
 
 
 
 
 
 
 
 
4a68fe0
 
 
 
3e0a1b1
4a68fe0
 
 
 
 
 
 
3e0a1b1
 
4a68fe0
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import streamlit as st
from streamlit_option_menu import option_menu
from generate_plot import generate_plot, generate_storybook, generate_book_cover, set_openai_api_key
from generate_horror_plot import generate_horror_plot, generate_horror_storybook, set_openai_api_key
from markup import app_intro, how_use_intro
from g4f import Provider


if "generated_code" not in st.session_state:
    st.session_state["generated_code"] = ""

if "generated_horror_code" not in st.session_state:
    st.session_state["generated_horror_code"] = ""

def tab1():

    col1, col2 = st.columns([1, 2])
    with col1:
        st.image("image.jpg", use_column_width=True)
    with col2:
        st.markdown(app_intro(), unsafe_allow_html=True)
    st.markdown(how_use_intro(),unsafe_allow_html=True) 


    github_link = '[<img src="https://badgen.net/badge/icon/github?icon=github&label">](https://github.com/ethanrom)'
    huggingface_link = '[<img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue">](https://huggingface.co/ethanrom)'

    st.write(github_link + '&nbsp;&nbsp;&nbsp;' + huggingface_link, unsafe_allow_html=True)

def tab2():
    st.header("πŸ“š Auto Children Story Generator 🎨")
    st.markdown("Create an enchanting children's book with custom characters and illustrations!")
    st.write("Follow the magical instructions below:")

    col1, col2 = st.columns(2)
    with col1:
        st.subheader("Step 1: Enter the Age πŸ§’")
        st.write("Enter the targeted age group (between 1 and 10) for your delightful readers.")
        age = st.number_input("Enter the targeted age:",  min_value=1, max_value=10, value=4)

        st.subheader("Step 2: Choose the Number of Pages πŸ“–")
        st.write("Select the number of pages for your captivating children's book (between 2 and 7).")
        number_of_pages = st.number_input("Enter the Number of Pages:",  min_value=2, max_value=7, value=3)

    with col2:
        st.subheader("Step 3: Name Your Characters 🌟")
        st.write("Enter the names of the endearing characters you wish to bring to life in the story.")
        character_names = st.text_area("Enter Character names here:", value="Lilly")

        st.subheader("Step 4: Choose the Art Style 🎨")
        st.write("Select the art style that will add magic to your children's book illustrations.")
        art_styles = ["Style 1", "Style 2", "Style 3"]
        selected_style = st.selectbox("Select Art Style:", art_styles)

    result = None
    st.subheader("Step 5: Choose API πŸ”Œ")
    st.write("Select between G4F free providers or OpenAI. Please note that some G4F providers may not work all time. If it gives any errors for G4F try other providers or use OpenAI api key")
    provider = st.selectbox("Select API:", ["G4F", "OpenAI"])
    
    if provider == "OpenAI":
        openai_api_key = st.text_input("πŸ”‘ Enter your OpenAI API key:", type='password')
        if st.button("Generate Plot") and openai_api_key:
            set_openai_api_key(openai_api_key)
            with st.spinner('Generating plot...'):
                result = generate_plot(number_of_pages, character_names, age, selected_style, provider="OpenAI")
            st.code(result)
            st.session_state.generated_code = result
        elif not openai_api_key:
            st.warning("Please enter your OpenAI API key.")
    elif provider == "G4F":
        selected_provider = st.selectbox("Select G4F Provider:", [
            "Ails", "You", "Aichat", "Bard",
            "Forefront", "DeepAi", "GetGpt"
        ])
        if st.button("Generate Plot"):
            with st.spinner('Generating plot...'):
                result = generate_plot(number_of_pages, character_names, age, selected_style, provider="G4F", selected_provider=selected_provider)
            st.code(result)
            st.session_state.generated_code = result



    if st.button("Generate Storybook"):
        if not st.session_state.generated_code:
            st.warning("Please generate the plot first before creating the storybook.")
            return

        with st.spinner('Generating storybook...'):
            storybook = generate_storybook(st.session_state.generated_code)

        if len(storybook) == 0:
            st.error("Error: Unable to generate storybook.")
            return

        for page_number, image in storybook:
            st.markdown(f"<Page {page_number}>")
            st.image(image, use_column_width=True)


def tab3():
    st.header("πŸ•·οΈ Horror Story Generator 🏚️")
    st.markdown("Create a spine-chilling horror story with custom length and illustrations!")
    st.write("Follow the eerie instructions below:")

    #openai_api_key = st.text_input("πŸ”‘ Enter your OpenAI API key:", type='password')

    col1, col2 = st.columns(2)
    with col1:

        st.subheader("Step 1: Choose the Number of Pages πŸ“–")
        st.write("Select the number of pages for your bone-chilling horror story (between 2 and 7).")
        number_of_pages = st.number_input("Enter the Number of Pages:",  min_value=2, max_value=7, value=2)

    with col2:

        st.subheader("Step 2: Choose the Art Style 🎨")
        st.write("Select the art style that will add terror to your horror story illustrations.")
        art_styles = ["Style 1", "Style 2", "Style 3"]
        selected_style = st.selectbox("Select Art Style:", art_styles)

    result = None
    st.subheader("Step 3: Choose API πŸ”Œ")
    st.write("Select between G4F free providers or OpenAI. Please note that some G4F providers may not work all time")
    provider = st.selectbox("Select API:", ["G4F", "OpenAI"])

    if provider == "OpenAI":
        openai_api_key = st.text_input("πŸ”‘ Enter your OpenAI API key:", type='password')
        if st.button("Generate Plot") and openai_api_key:
            set_openai_api_key(openai_api_key)
            with st.spinner('Generating plot...'):
                result = generate_horror_plot(number_of_pages, selected_style, provider="OpenAI")
            st.code(result)
            st.session_state.generated_code = result
        elif not openai_api_key:
            st.warning("Please enter your OpenAI API key.")
    elif provider == "G4F":
        selected_provider = st.selectbox("Select G4F Provider:", [
            "Ails", "You", "Aichat", "Bard",
            "Forefront", "DeepAi", "GetGpt"
        ])
        if st.button("Generate Plot"):

            with st.spinner('Generating plot...'):
                result = generate_horror_plot(number_of_pages, selected_style, provider="G4F", selected_provider=selected_provider)
            st.code(result)
            st.session_state.generated_horror_code = result

    if st.button("Generate Horror Storybook"):
        if not st.session_state.generated_horror_code:
            st.warning("Please generate the plot first before creating the horror storybook.")
            return

        with st.spinner('Generating horror storybook...'):
            horror_storybook = generate_horror_storybook(st.session_state.generated_horror_code)

        if len(horror_storybook) == 0:
            st.error("Error: Unable to generate horror storybook.")
            return

        for page_number, image in horror_storybook:
            st.markdown(f"<Page {page_number}>")
            st.image(image, use_column_width=True)


def tab4():
    st.header("Book Cover Page Generator")
    st.markdown("Auto Generate a book cover for your children's storybook.")

    #openai_api_key = st.text_input("Enter your OpenAI API key:", type='password')

    st.subheader("Step 1: Enter Book Title")
    title = st.text_input("Enter Book Title:", value="Adventures of Lilly")

    st.subheader("Step 2: Enter Author Name")
    author = st.text_input("Enter Author Name:", value="Lilly's mom")

    st.subheader("Step 3: Enter Image Description")
    st.write("Enter a description of the image you want to use for the book cover.")
    image_text = st.text_area("Enter Image Description:", value="storybook art of a little girl's adventure")

    result = None

    if st.button("Generate Book Cover"):

        with st.spinner('Generating book cover...'):
            result = generate_book_cover(title, author, image_text)
        
        if len(result) == 0:
            st.warning("Error: Unable to generate book cover.")
            return

        for page_number, image in enumerate(result, start=1):
            st.markdown(f"<Cover Page>")
            st.image(image, use_column_width=True)



def main():
    st.set_page_config(page_title="Children storybook generator", page_icon=":memo:", layout="wide")
    tabs = ["Intro", "Children", "Horror"]

    with st.sidebar:

        current_tab = option_menu("Select a Tab", tabs, menu_icon="cast")

    tab_functions = {
    "Intro": tab1,
    "Children": tab2,
    "Horror": tab3,
    }

    if current_tab in tab_functions:
        tab_functions[current_tab]()

if __name__ == "__main__":
    main()