AI-ANK commited on
Commit
34026b8
·
1 Parent(s): 9149fd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
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
- # Convert BytesIO to PIL Image
34
- image = Image.open(io.BytesIO(image_data))
 
 
 
 
 
 
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