Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
import streamlit as st
|
| 3 |
from PIL import Image
|
| 4 |
from gtts import gTTS
|
|
@@ -7,21 +7,20 @@ import time
|
|
| 7 |
|
| 8 |
from transformers import pipeline
|
| 9 |
|
| 10 |
-
|
| 11 |
def image_to_caption(image_path):
|
| 12 |
-
"""Generates a caption for the given image using a pre-trained model."""
|
| 13 |
imgtocaption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 14 |
caption = imgtocaption(image_path)[0]['generated_text']
|
| 15 |
return caption
|
| 16 |
|
|
|
|
| 17 |
def caption_to_story(text):
|
| 18 |
-
"""Generates a story for the caption using a pre-trained model."""
|
| 19 |
captiontostory = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 20 |
story = captiontostory(text,max_length=150,min_length=50)[0]['generated_text']
|
| 21 |
return story
|
| 22 |
|
|
|
|
| 23 |
def story_to_audio(text):
|
| 24 |
-
"""Generates an audio for the story."""
|
| 25 |
audio = io.BytesIO()
|
| 26 |
tts = gTTS(text=text, lang='en', slow=False)
|
| 27 |
tts.write_to_fp(audio)
|
|
@@ -37,7 +36,7 @@ st.markdown("Upload an image and generate your exclusive fairy tale!")
|
|
| 37 |
# File Upload
|
| 38 |
uploaded_image = st.file_uploader("Choose a picture", type=["jpg", "jpeg", "png"], key="image_uploader")
|
| 39 |
|
| 40 |
-
#
|
| 41 |
if uploaded_image is not None:
|
| 42 |
# Display the uploaded image
|
| 43 |
st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)
|
|
|
|
| 1 |
+
# Import Part
|
| 2 |
import streamlit as st
|
| 3 |
from PIL import Image
|
| 4 |
from gtts import gTTS
|
|
|
|
| 7 |
|
| 8 |
from transformers import pipeline
|
| 9 |
|
| 10 |
+
# Generates a caption for the given image using a pre-trained model.
|
| 11 |
def image_to_caption(image_path):
|
|
|
|
| 12 |
imgtocaption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 13 |
caption = imgtocaption(image_path)[0]['generated_text']
|
| 14 |
return caption
|
| 15 |
|
| 16 |
+
# Generates a story for the caption using a pre-trained model.
|
| 17 |
def caption_to_story(text):
|
|
|
|
| 18 |
captiontostory = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 19 |
story = captiontostory(text,max_length=150,min_length=50)[0]['generated_text']
|
| 20 |
return story
|
| 21 |
|
| 22 |
+
# Generates an audio for the story.
|
| 23 |
def story_to_audio(text):
|
|
|
|
| 24 |
audio = io.BytesIO()
|
| 25 |
tts = gTTS(text=text, lang='en', slow=False)
|
| 26 |
tts.write_to_fp(audio)
|
|
|
|
| 36 |
# File Upload
|
| 37 |
uploaded_image = st.file_uploader("Choose a picture", type=["jpg", "jpeg", "png"], key="image_uploader")
|
| 38 |
|
| 39 |
+
# Main Part
|
| 40 |
if uploaded_image is not None:
|
| 41 |
# Display the uploaded image
|
| 42 |
st.image(uploaded_image, caption='Uploaded Image', use_column_width=True)
|