Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,11 +15,10 @@ except ImportError:
|
|
15 |
import torch
|
16 |
|
17 |
# Load the image captioning model
|
18 |
-
caption_model = pipeline("image-to-text", model="
|
19 |
|
20 |
-
# Load the
|
21 |
-
|
22 |
-
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
23 |
|
24 |
def generate_caption(image):
|
25 |
# Generate the caption for the uploaded image
|
@@ -27,11 +26,10 @@ def generate_caption(image):
|
|
27 |
return caption
|
28 |
|
29 |
def generate_story(caption):
|
30 |
-
# Generate the story based on the caption
|
31 |
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."
|
32 |
-
|
33 |
-
|
34 |
-
story = tokenizer.decode(output[0], skip_special_tokens=True)
|
35 |
return story
|
36 |
|
37 |
def convert_to_audio(story):
|
@@ -60,7 +58,7 @@ def main():
|
|
60 |
st.subheader("Generated Caption:")
|
61 |
st.write(caption)
|
62 |
|
63 |
-
# Generate the story based on the caption
|
64 |
story = generate_story(caption)
|
65 |
st.subheader("Generated Story:")
|
66 |
st.write(story)
|
|
|
15 |
import torch
|
16 |
|
17 |
# Load the image captioning model
|
18 |
+
caption_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
19 |
|
20 |
+
# Load the DeepSeek model for story generation
|
21 |
+
story_generator = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True)
|
|
|
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 DeepSeek 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 |
+
messages = [{"role": "user", "content": prompt}]
|
32 |
+
story = story_generator(messages)[0]["generated_text"]
|
|
|
33 |
return story
|
34 |
|
35 |
def convert_to_audio(story):
|
|
|
58 |
st.subheader("Generated Caption:")
|
59 |
st.write(caption)
|
60 |
|
61 |
+
# Generate the story based on the caption using the DeepSeek model
|
62 |
story = generate_story(caption)
|
63 |
st.subheader("Generated Story:")
|
64 |
st.write(story)
|