Szeyu commited on
Commit
822643b
ยท
verified ยท
1 Parent(s): f0a6b70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -28,7 +28,8 @@ def generate_content(image):
28
 
29
  # Generate a caption based on the image content
30
  caption = captioner(pil_image)[0]["generated_text"]
31
- st.write("**Caption:**", caption)
 
32
 
33
  # Create a prompt for generating a children's story
34
  prompt = (
@@ -50,7 +51,8 @@ def generate_content(image):
50
  # Trim the generated story to a maximum of 100 words
51
  words = raw.split()
52
  story = " ".join(words[:100])
53
- st.write("**Story:**", story)
 
54
 
55
  # Split the story into chunks of 200 characters for text-to-speech processing
56
  chunks = textwrap.wrap(story, width=200)
@@ -66,26 +68,26 @@ def generate_content(image):
66
  return caption, story, temp_file_path
67
 
68
  # Streamlit UI for the application
69
- st.title("Image to Children's Story and Audio")
70
- st.markdown("""
71
- Upload an image below to generate a caption, a funny children's story,
72
- and an audio narration based on the image. The story will be tailored
73
- for children aged 3-10.
74
- """)
75
 
76
  # File uploader for image input
77
- uploaded_image = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"], help="Supported formats: JPG, JPEG, PNG")
78
 
79
- if uploaded_image is not None:
80
- # Display the uploaded image with a caption
81
- st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
82
-
83
- # Button to trigger content generation
84
- if st.button("Generate Story and Audio", help="Click to create the story and audio"):
85
- # Show a spinner while content is being generated
86
- with st.spinner("Generating your story and audio narration..."):
 
 
 
87
  caption, story, audio_path = generate_content(uploaded_image)
88
- # Display the audio player with the generated narration
89
  st.audio(audio_path, format="audio/wav")
90
- # Remove the temporary audio file after use
91
- os.remove(audio_path)
 
 
28
 
29
  # Generate a caption based on the image content
30
  caption = captioner(pil_image)[0]["generated_text"]
31
+ st.write("**๐ŸŒŸ What's in the picture: ๐ŸŒŸ**")
32
+ st.write(caption)
33
 
34
  # Create a prompt for generating a children's story
35
  prompt = (
 
51
  # Trim the generated story to a maximum of 100 words
52
  words = raw.split()
53
  story = " ".join(words[:100])
54
+ st.write("**๐Ÿ“– Your funny story: ๐Ÿ“–**")
55
+ st.write(story)
56
 
57
  # Split the story into chunks of 200 characters for text-to-speech processing
58
  chunks = textwrap.wrap(story, width=200)
 
68
  return caption, story, temp_file_path
69
 
70
  # Streamlit UI for the application
71
+ st.title("โœจ Magic Story Maker โœจ")
72
+ st.markdown("Upload a picture to make a funny story and hear it too! ๐Ÿ“ธ")
 
 
 
 
73
 
74
  # File uploader for image input
75
+ uploaded_image = st.file_uploader("Choose your picture", type=["jpg", "jpeg", "png"], help="Pick a photo to start the magic!")
76
 
77
+ # Placeholder image URL (replace with an actual URL of a child-friendly image)
78
+ placeholder_url = "https://example.com/placeholder_image.jpg"
79
+
80
+ if uploaded_image is None:
81
+ st.image(placeholder_url, caption="Upload your picture here! ๐Ÿ“ท", use_column_width=True)
82
+ else:
83
+ st.image(uploaded_image, caption="Your Picture ๐ŸŒŸ", use_column_width=True)
84
+
85
+ if st.button("โœจ Make My Story! โœจ", help="Click to create your magic story"):
86
+ if uploaded_image is not None:
87
+ with st.spinner("๐Ÿ”ฎ Creating your magical story..."):
88
  caption, story, audio_path = generate_content(uploaded_image)
89
+ st.success("๐ŸŽ‰ Your story is ready! ๐ŸŽ‰")
90
  st.audio(audio_path, format="audio/wav")
91
+ os.remove(audio_path)
92
+ else:
93
+ st.warning("Please upload a picture first! ๐Ÿ“ธ")