Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,8 +17,8 @@ except ImportError:
|
|
| 17 |
# Load the image captioning model
|
| 18 |
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 19 |
|
| 20 |
-
# Load the
|
| 21 |
-
story_generator = pipeline("text-generation", model="
|
| 22 |
|
| 23 |
def generate_caption(image):
|
| 24 |
# Generate the caption for the uploaded image
|
|
@@ -26,10 +26,9 @@ def generate_caption(image):
|
|
| 26 |
return caption
|
| 27 |
|
| 28 |
def generate_story(caption):
|
| 29 |
-
# Generate the story based on the caption using the
|
| 30 |
prompt = f"Imagine you are a storyteller for young children. Based on the image described as '{caption}', create a short and interesting story for children aged 3-10. Keep it positive and happy in tone."
|
| 31 |
-
|
| 32 |
-
story = story_generator(messages)[0]["generated_text"]
|
| 33 |
return story
|
| 34 |
|
| 35 |
def convert_to_audio(story):
|
|
@@ -58,7 +57,7 @@ def main():
|
|
| 58 |
st.subheader("Generated Caption:")
|
| 59 |
st.write(caption)
|
| 60 |
|
| 61 |
-
# Generate the story based on the caption using the
|
| 62 |
story = generate_story(caption)
|
| 63 |
st.subheader("Generated Story:")
|
| 64 |
st.write(story)
|
|
|
|
| 17 |
# Load the image captioning model
|
| 18 |
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 19 |
|
| 20 |
+
# Load the GPT-2 model for story generation
|
| 21 |
+
story_generator = pipeline("text-generation", model="gpt2")
|
| 22 |
|
| 23 |
def generate_caption(image):
|
| 24 |
# Generate the caption for the uploaded image
|
|
|
|
| 26 |
return caption
|
| 27 |
|
| 28 |
def generate_story(caption):
|
| 29 |
+
# Generate the story based on the caption using the GPT-2 model
|
| 30 |
prompt = f"Imagine you are a storyteller for young children. Based on the image described as '{caption}', create a short and interesting story for children aged 3-10. Keep it positive and happy in tone."
|
| 31 |
+
story = story_generator(prompt, max_length=200, num_return_sequences=1)[0]["generated_text"]
|
|
|
|
| 32 |
return story
|
| 33 |
|
| 34 |
def convert_to_audio(story):
|
|
|
|
| 57 |
st.subheader("Generated Caption:")
|
| 58 |
st.write(caption)
|
| 59 |
|
| 60 |
+
# Generate the story based on the caption using the GPT-2 model
|
| 61 |
story = generate_story(caption)
|
| 62 |
st.subheader("Generated Story:")
|
| 63 |
st.write(story)
|