Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ import torch
|
|
6 |
|
7 |
st.set_page_config(page_title="Image-to-Audio Story Generator", page_icon="π¦")
|
8 |
|
9 |
-
|
10 |
def create_image_caption(image_file):
|
11 |
pil_image = Image.open(image_file)
|
12 |
caption_generator = pipeline(
|
@@ -17,7 +16,7 @@ def create_image_caption(image_file):
|
|
17 |
generated_caption = caption_result[0]["generated_text"]
|
18 |
return generated_caption
|
19 |
|
20 |
-
def build_children_story(
|
21 |
story_generator = pipeline(
|
22 |
"text-generation",
|
23 |
model="Qwen/Qwen2.5-0.5B-Instruct",
|
@@ -28,10 +27,10 @@ def build_children_story(image_description):
|
|
28 |
"Using the details derived from the image below, craft a complete and captivating tale that includes three main characters, "
|
29 |
"an adventurous journey, and delightful surprises. "
|
30 |
"Your story should have a clear beginning, middle, and end, and be between 80 and 100 words in length.\n\n"
|
31 |
-
f"Image Details: {
|
32 |
)
|
33 |
|
34 |
-
generated_output =
|
35 |
story_prompt,
|
36 |
max_new_tokens=150,
|
37 |
num_return_sequences=1,
|
@@ -63,13 +62,11 @@ def build_children_story(image_description):
|
|
63 |
|
64 |
return story_text
|
65 |
|
66 |
-
|
67 |
def convert_text_to_audio(story_content, audio_file_name="output.mp3"):
|
68 |
tts = gTTS(text=story_content, lang="en")
|
69 |
tts.save(audio_file_name)
|
70 |
return audio_file_name
|
71 |
|
72 |
-
|
73 |
def main_app():
|
74 |
st.markdown("<h1 style='text-align: center;'>Image-to-Audio Story Generator π¦</h1>", unsafe_allow_html=True)
|
75 |
st.write("Upload an image below to generate an engaging story from the picture, then convert the story into audio playback!")
|
@@ -93,6 +90,4 @@ def main_app():
|
|
93 |
audio_file_name = convert_text_to_audio(story_content)
|
94 |
st.audio(audio_file_name, format="audio/mp3")
|
95 |
|
96 |
-
|
97 |
-
if __name__ == "__main__":
|
98 |
-
main_app()
|
|
|
6 |
|
7 |
st.set_page_config(page_title="Image-to-Audio Story Generator", page_icon="π¦")
|
8 |
|
|
|
9 |
def create_image_caption(image_file):
|
10 |
pil_image = Image.open(image_file)
|
11 |
caption_generator = pipeline(
|
|
|
16 |
generated_caption = caption_result[0]["generated_text"]
|
17 |
return generated_caption
|
18 |
|
19 |
+
def build_children_story(image_caption): # Updated parameter name
|
20 |
story_generator = pipeline(
|
21 |
"text-generation",
|
22 |
model="Qwen/Qwen2.5-0.5B-Instruct",
|
|
|
27 |
"Using the details derived from the image below, craft a complete and captivating tale that includes three main characters, "
|
28 |
"an adventurous journey, and delightful surprises. "
|
29 |
"Your story should have a clear beginning, middle, and end, and be between 80 and 100 words in length.\n\n"
|
30 |
+
f"Image Details: {image_caption}\n\nStory:"
|
31 |
)
|
32 |
|
33 |
+
generated_output = story_generator(
|
34 |
story_prompt,
|
35 |
max_new_tokens=150,
|
36 |
num_return_sequences=1,
|
|
|
62 |
|
63 |
return story_text
|
64 |
|
|
|
65 |
def convert_text_to_audio(story_content, audio_file_name="output.mp3"):
|
66 |
tts = gTTS(text=story_content, lang="en")
|
67 |
tts.save(audio_file_name)
|
68 |
return audio_file_name
|
69 |
|
|
|
70 |
def main_app():
|
71 |
st.markdown("<h1 style='text-align: center;'>Image-to-Audio Story Generator π¦</h1>", unsafe_allow_html=True)
|
72 |
st.write("Upload an image below to generate an engaging story from the picture, then convert the story into audio playback!")
|
|
|
90 |
audio_file_name = convert_text_to_audio(story_content)
|
91 |
st.audio(audio_file_name, format="audio/mp3")
|
92 |
|
93 |
+
if __name__ == "__main
|
|
|
|