Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,8 +30,14 @@ model, processor = get_vision_model()
|
|
| 30 |
# Function to get image caption via Kosmos2.
|
| 31 |
@st.cache_data
|
| 32 |
def get_image_caption(image_data):
|
| 33 |
-
#
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
model, processor = get_vision_model()
|
| 37 |
|
|
|
|
| 30 |
# Function to get image caption via Kosmos2.
|
| 31 |
@st.cache_data
|
| 32 |
def get_image_caption(image_data):
|
| 33 |
+
# Ensure image_data is a bytes stream ready to be read by Image.open
|
| 34 |
+
if isinstance(image_data, io.BytesIO):
|
| 35 |
+
# If it's already a BytesIO, we need to seek to the beginning of the file
|
| 36 |
+
image_data.seek(0)
|
| 37 |
+
image = Image.open(image_data)
|
| 38 |
+
else:
|
| 39 |
+
# If image_data is not a BytesIO object, create one
|
| 40 |
+
image = Image.open(io.BytesIO(image_data.read()))
|
| 41 |
|
| 42 |
model, processor = get_vision_model()
|
| 43 |
|