Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ def load_models():
|
|
14 |
return caption_model, story_model, tts_model # Return all three models
|
15 |
|
16 |
# Function to generate story from caption
|
17 |
-
def generate_story(caption):
|
18 |
# Generate a story based on the caption
|
19 |
story = story_model(caption, max_length=100, num_return_sequences=1)[0]['generated_text'] # Generate the story
|
20 |
return story # Return the generated story
|
@@ -25,16 +25,17 @@ def text_to_audio(text, tts_model):
|
|
25 |
return audio # Return the audio object
|
26 |
|
27 |
# Function to process the uploaded image and generate a story
|
28 |
-
def process_image(image, caption_model):
|
29 |
# Generate a caption from the uploaded image
|
30 |
-
|
|
|
31 |
# Generate a story from the caption
|
32 |
-
story = generate_story(caption) # Call the story generation function
|
33 |
return caption, story # Return both caption and story
|
34 |
|
35 |
# Main part
|
36 |
def main():
|
37 |
-
st.set_page_config(page_title="Storytelling Friend", page_icon="🦦")
|
38 |
st.write("Upload an image to generate a story!") # Instructions for the user
|
39 |
|
40 |
# Upload image section
|
@@ -46,10 +47,10 @@ def main():
|
|
46 |
if uploaded_file is not None:
|
47 |
# Open and read the uploaded image
|
48 |
image = Image.open(uploaded_file) # Open the uploaded image file
|
49 |
-
st.image(image, caption="Uploaded Image",
|
50 |
|
51 |
# Process the image and generate story
|
52 |
-
caption, story = process_image(image, caption_model) # Get caption and story
|
53 |
st.subheader("Generated Caption:") # Subheader for caption
|
54 |
st.write(caption) # Display the caption
|
55 |
st.subheader("Generated Story:") # Subheader for story
|
|
|
14 |
return caption_model, story_model, tts_model # Return all three models
|
15 |
|
16 |
# Function to generate story from caption
|
17 |
+
def generate_story(caption, story_model):
|
18 |
# Generate a story based on the caption
|
19 |
story = story_model(caption, max_length=100, num_return_sequences=1)[0]['generated_text'] # Generate the story
|
20 |
return story # Return the generated story
|
|
|
25 |
return audio # Return the audio object
|
26 |
|
27 |
# Function to process the uploaded image and generate a story
|
28 |
+
def process_image(image, caption_model, story_model):
|
29 |
# Generate a caption from the uploaded image
|
30 |
+
result = caption_model(image) # Get the result from the model
|
31 |
+
caption = result[0]['generated_text'] # Access the generated caption
|
32 |
# Generate a story from the caption
|
33 |
+
story = generate_story(caption, story_model) # Call the story generation function
|
34 |
return caption, story # Return both caption and story
|
35 |
|
36 |
# Main part
|
37 |
def main():
|
38 |
+
st.set_page_config(page_title="Storytelling Friend", page_icon="🦦") # Title of the application
|
39 |
st.write("Upload an image to generate a story!") # Instructions for the user
|
40 |
|
41 |
# Upload image section
|
|
|
47 |
if uploaded_file is not None:
|
48 |
# Open and read the uploaded image
|
49 |
image = Image.open(uploaded_file) # Open the uploaded image file
|
50 |
+
st.image(image, caption="Uploaded Image", use_container_width=True) # Display the uploaded image
|
51 |
|
52 |
# Process the image and generate story
|
53 |
+
caption, story = process_image(image, caption_model, story_model) # Get caption and story
|
54 |
st.subheader("Generated Caption:") # Subheader for caption
|
55 |
st.write(caption) # Display the caption
|
56 |
st.subheader("Generated Story:") # Subheader for story
|