Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,8 +17,6 @@ except ImportError:
|
|
17 |
# Load the image captioning model
|
18 |
caption_model = pipeline("image-to-text", model="unography/blip-large-long-cap")
|
19 |
|
20 |
-
# Load the GPT-2 model for story generation
|
21 |
-
#story_generator = pipeline("text-generation", model="gpt2")
|
22 |
story_generator = pipeline("text-generation", model="distilbert/distilgpt2")
|
23 |
|
24 |
def generate_caption(image):
|
@@ -26,24 +24,9 @@ def generate_caption(image):
|
|
26 |
caption = caption_model(image)[0]["generated_text"]
|
27 |
return caption
|
28 |
|
29 |
-
#def generate_story(caption):
|
30 |
-
# Generate the story based on the caption using the GPT-2 model
|
31 |
-
#prompt = f"Starting with 'Once upon a time', based on the image described as '{caption}', here is a short and interesting story for children aged 3-10. The story is positive and happy in tone, with added imagination:\n\n"
|
32 |
-
#story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
|
33 |
-
|
34 |
-
# Extract the story text from the generated output
|
35 |
-
#story = story.split("\n\n")[1].strip()
|
36 |
-
|
37 |
-
#return story
|
38 |
-
|
39 |
-
#def generate_story(caption):
|
40 |
-
# Generate the story based on the caption
|
41 |
-
#story = story_generator(caption, max_length=200, num_return_sequences=1)[0]["generated_text"]
|
42 |
-
#return story
|
43 |
-
|
44 |
def generate_story(caption):
|
45 |
# Generate the story based on the caption using the GPT-2 model
|
46 |
-
prompt = f"Once upon a time, based on the image described as '{caption}', here is a short, simple, and engaging story for children aged 3-10. The story should be easy to understand, use age-appropriate language, and convey a positive message. Focus on the main elements in the image and create a story that sparks their imagination:\n\n"
|
47 |
story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
|
48 |
|
49 |
# Extract the story text from the generated output
|
@@ -61,7 +44,6 @@ def generate_story(caption):
|
|
61 |
|
62 |
return story
|
63 |
|
64 |
-
|
65 |
def convert_to_audio(story):
|
66 |
# Convert the story to audio using gTTS
|
67 |
tts = gTTS(text=story, lang="en")
|
|
|
17 |
# Load the image captioning model
|
18 |
caption_model = pipeline("image-to-text", model="unography/blip-large-long-cap")
|
19 |
|
|
|
|
|
20 |
story_generator = pipeline("text-generation", model="distilbert/distilgpt2")
|
21 |
|
22 |
def generate_caption(image):
|
|
|
24 |
caption = caption_model(image)[0]["generated_text"]
|
25 |
return caption
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def generate_story(caption):
|
28 |
# Generate the story based on the caption using the GPT-2 model
|
29 |
+
prompt = f"Startig with 'Once upon a time...', also, based on the image described as '{caption}', here is a short, simple, and engaging story for children aged 3-10. The story should be easy to understand, use age-appropriate language, and convey a positive message. Focus on the main elements in the image and create a story that sparks their imagination:\n\n"
|
30 |
story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
|
31 |
|
32 |
# Extract the story text from the generated output
|
|
|
44 |
|
45 |
return story
|
46 |
|
|
|
47 |
def convert_to_audio(story):
|
48 |
# Convert the story to audio using gTTS
|
49 |
tts = gTTS(text=story, lang="en")
|