nniehaus commited on
Commit
6ff2402
·
1 Parent(s): b094eac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -9,14 +9,15 @@ openai.api_key = st.secrets["OPENAI_API_KEY"]
9
 
10
  st.title("Children's Story and Image Panel Generator")
11
 
12
- # User inputs for the story
13
  age_group = st.selectbox("Age Group", ["3-5 years", "6-8 years", "9-12 years"])
14
  theme = st.text_input("Story Theme", placeholder="Enter a theme for the story (e.g., adventure, friendship)")
15
- details = st.text_area("Additional Details", placeholder="Any specific details to include in the story (e.g., a brave rabbit, a magical forest)")
 
16
 
17
  # Function to generate the story
18
- def generate_story(age_group, theme, details):
19
- prompt = f"Write a concise children's story suitable for age group {age_group} about {theme}. Include details such as {details}. The story should be short enough to fit within 10 panels."
20
  response = openai.ChatCompletion.create(
21
  model="gpt-4",
22
  messages=[
@@ -28,10 +29,11 @@ def generate_story(age_group, theme, details):
28
  return response.choices[0].message['content']
29
 
30
  # Function to generate images with DALL-E 3
31
- def generate_image(panel_text):
32
  try:
 
33
  response = openai.Image.create(
34
- prompt=panel_text,
35
  n=1,
36
  size="1024x1024", # Adjust the size if needed
37
  model="dall-e-3" # Specify DALL-E 3 model
@@ -45,13 +47,13 @@ def generate_image(panel_text):
45
  return None
46
 
47
  if st.button('Generate Story and Images'):
48
- story = generate_story(age_group, theme, details)
49
  story_parts = story.split('.')[:10] # Use the first 10 sentences for panels
50
 
51
  for i, part in enumerate(story_parts):
52
  if part.strip(): # Ensure part is not empty
53
  st.subheader(f'Panel {i+1}')
54
  st.write(part.strip())
55
- image = generate_image(part)
56
  if image:
57
  st.image(image, caption=f'Image for Panel {i+1}')
 
9
 
10
  st.title("Children's Story and Image Panel Generator")
11
 
12
+ # User inputs for the story and main character
13
  age_group = st.selectbox("Age Group", ["3-5 years", "6-8 years", "9-12 years"])
14
  theme = st.text_input("Story Theme", placeholder="Enter a theme for the story (e.g., adventure, friendship)")
15
+ main_character = st.text_input("Main Character", placeholder="Describe the main character (e.g., a small brave rabbit)")
16
+ details = st.text_area("Additional Details", placeholder="Any specific details to include in the story (e.g., a magical forest)")
17
 
18
  # Function to generate the story
19
+ def generate_story(age_group, theme, main_character, details):
20
+ prompt = f"Write a concise children's story suitable for age group {age_group} about {theme} featuring a main character who is {main_character}. Include details such as {details}. The story should be short enough to fit within 10 panels."
21
  response = openai.ChatCompletion.create(
22
  model="gpt-4",
23
  messages=[
 
29
  return response.choices[0].message['content']
30
 
31
  # Function to generate images with DALL-E 3
32
+ def generate_image(panel_text, main_character):
33
  try:
34
+ prompt = f"{panel_text}. Visual style: consistent with previous panels. Main character: {main_character}."
35
  response = openai.Image.create(
36
+ prompt=prompt,
37
  n=1,
38
  size="1024x1024", # Adjust the size if needed
39
  model="dall-e-3" # Specify DALL-E 3 model
 
47
  return None
48
 
49
  if st.button('Generate Story and Images'):
50
+ story = generate_story(age_group, theme, main_character, details)
51
  story_parts = story.split('.')[:10] # Use the first 10 sentences for panels
52
 
53
  for i, part in enumerate(story_parts):
54
  if part.strip(): # Ensure part is not empty
55
  st.subheader(f'Panel {i+1}')
56
  st.write(part.strip())
57
+ image = generate_image(part, main_character)
58
  if image:
59
  st.image(image, caption=f'Image for Panel {i+1}')