Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
# import part - only using the two requested imports
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
|
|
|
|
4 |
|
5 |
# function part
|
6 |
# img2text
|
7 |
-
def img2text(
|
8 |
image_to_text = pipeline("image-to-text", model="sooh-j/blip-image-captioning-base")
|
9 |
-
text = image_to_text(
|
10 |
return text
|
11 |
|
12 |
# text2story - IMPROVED to end naturally
|
@@ -91,12 +93,12 @@ if uploaded_file is not None:
|
|
91 |
# Display the uploaded image
|
92 |
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
|
93 |
|
94 |
-
#
|
95 |
-
|
96 |
|
97 |
# Stage 1: Image to Text
|
98 |
st.text('Processing img2text...')
|
99 |
-
caption = img2text(
|
100 |
st.write(caption)
|
101 |
|
102 |
# Stage 2: Text to Story
|
|
|
1 |
# import part - only using the two requested imports
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
|
7 |
# function part
|
8 |
# img2text
|
9 |
+
def img2text(image):
|
10 |
image_to_text = pipeline("image-to-text", model="sooh-j/blip-image-captioning-base")
|
11 |
+
text = image_to_text(image)[0]["generated_text"]
|
12 |
return text
|
13 |
|
14 |
# text2story - IMPROVED to end naturally
|
|
|
93 |
# Display the uploaded image
|
94 |
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
|
95 |
|
96 |
+
# Convert the file to a PIL Image
|
97 |
+
image = Image.open(uploaded_file)
|
98 |
|
99 |
# Stage 1: Image to Text
|
100 |
st.text('Processing img2text...')
|
101 |
+
caption = img2text(image) # Pass PIL image to pipeline
|
102 |
st.write(caption)
|
103 |
|
104 |
# Stage 2: Text to Story
|