Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,12 @@ import streamlit as st
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# function part
|
| 6 |
-
#
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
|
@@ -15,30 +16,28 @@ def text2story(text):
|
|
| 15 |
story_text = pipe(text)[0]['generated_text']
|
| 16 |
return story_text
|
| 17 |
|
| 18 |
-
|
| 19 |
-
def text2audio(story_text):
|
| 20 |
-
pipe = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
|
| 21 |
-
audio_data = pipe(story_text)
|
| 22 |
-
return audio_data
|
| 23 |
|
| 24 |
|
| 25 |
def main():
|
| 26 |
-
|
| 27 |
-
st.
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if uploaded_file is not None:
|
| 31 |
print(uploaded_file)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
file.write(bytes_data)
|
| 35 |
-
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 36 |
|
| 37 |
|
| 38 |
#Stage 1: Image to Text
|
| 39 |
st.text('Processing img2text...')
|
| 40 |
-
|
| 41 |
-
st.write(
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
main()
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# function part
|
| 6 |
+
# function part
|
| 7 |
+
def generate_image_caption(image_path):
|
| 8 |
+
"""Generates a caption for the given image using a pre-trained model."""
|
| 9 |
+
img2caption = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 10 |
+
result = img2caption(image_path)
|
| 11 |
+
return result[0]['generated_text']
|
| 12 |
|
| 13 |
# text2story
|
| 14 |
def text2story(text):
|
|
|
|
| 16 |
story_text = pipe(text)[0]['generated_text']
|
| 17 |
return story_text
|
| 18 |
|
| 19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def main():
|
| 23 |
+
# App title
|
| 24 |
+
st.title("Streamlit Demo on Hugging Face")
|
| 25 |
+
|
| 26 |
+
# Write some text
|
| 27 |
+
st.write("Welcome to a demo app showcasing basic Streamlit components!")
|
| 28 |
+
|
| 29 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 30 |
|
| 31 |
if uploaded_file is not None:
|
| 32 |
print(uploaded_file)
|
| 33 |
+
|
| 34 |
+
st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
#Stage 1: Image to Text
|
| 38 |
st.text('Processing img2text...')
|
| 39 |
+
image_caption = generate_image_caption(uploaded_image.name)
|
| 40 |
+
st.write(image_caption)
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
main()
|