import streamlit as st
import openai
# load and set our key
openai.api_key = open("key.txt", "r").read().strip("\n")
st.write("
Bedtime Story Teller with ChatGPT
", 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',
)