File size: 2,118 Bytes
15451a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import openai

# load and set our key
openai.api_key = open("key.txt", "r").read().strip("\n")

st.write("<center><h1>Bedtime Story Teller with ChatGPT</h1></center>", unsafe_allow_html=True)

#st.image(img_banner)

# Description
st.write("Welcome to the Bedtime Story Teller with ChatGPT! Get ready for a delightful storytelling experience.")

def generate_story(keyword, writing_style, age, word_count):
    #return "This is a test article generated without making API calls."
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
                {"role": "user", "content": "Write a creative and interesting Bedtime about " + keyword},
                {"role": "user", "content": "The story should be " + writing_style},
                {"role": "user", "content": "The langugage and tone the story should target kids around the age" + str(age)},
                {"role": "user", "content": "The story length should " + str(word_count)},
                {"role": "user", "content": "The story length should have a strong moral undertone"},
            ]
    )
    result = ''

    for choice in response.choices:
        result += choice.message.content

    print(result)
    return result

keyword = st.text_input("Enter a keyword:")
writing_style = st.selectbox("Select writing style:", ["African Short Stories", "African folktale", "African sci-fi", "African Magical Realism",
                            "African Thrillers/Mystery", "African Mythology", "African Historical Fiction"])
age = st.slider("Select Age of kid:", min_value=1, max_value=15, step=1, value=1)
word_count = st.slider("Select word count:", min_value=300, max_value=1000, step=100, value=300)
submit_button = st.button("Generate Story")

if submit_button:
    message = st.empty()
    message.text("Busy generating...")
    article = generate_story(keyword, writing_style, age,  word_count)
    message.text("")
    st.write(article)
    st.download_button(
        label="Download Story",
        data=article,
        file_name= 'Story.txt',
        mime='text/txt',
    )