sunheycho commited on
Commit
be7a2aa
Β·
1 Parent(s): 4e3ec65

Fix 'read of closed file' error in ImageProcessingAgent

Browse files

- Load images fully into memory with .convert('RGB') to avoid file stream closure issues
- Ensures ViT model can access image data after stream is closed
- Fixes product comparison session error status

Files changed (1) hide show
  1. api.py +6 -2
api.py CHANGED
@@ -1009,7 +1009,9 @@ def start_product_comparison():
1009
  img1 = request.files['image1']
1010
  print(f"[DEBUG] πŸ–ΌοΈ Processing image1: {img1.filename}")
1011
  try:
1012
- images.append(Image.open(img1.stream))
 
 
1013
  print(f"[DEBUG] βœ… Image1 processed successfully")
1014
  except Exception as e:
1015
  print(f"[DEBUG] ❌ Error processing image1: {e}")
@@ -1018,7 +1020,9 @@ def start_product_comparison():
1018
  img2 = request.files['image2']
1019
  print(f"[DEBUG] πŸ–ΌοΈ Processing image2: {img2.filename}")
1020
  try:
1021
- images.append(Image.open(img2.stream))
 
 
1022
  print(f"[DEBUG] βœ… Image2 processed successfully")
1023
  except Exception as e:
1024
  print(f"[DEBUG] ❌ Error processing image2: {e}")
 
1009
  img1 = request.files['image1']
1010
  print(f"[DEBUG] πŸ–ΌοΈ Processing image1: {img1.filename}")
1011
  try:
1012
+ # Load image and convert to RGB to ensure it's fully loaded in memory
1013
+ image = Image.open(img1.stream).convert('RGB')
1014
+ images.append(image)
1015
  print(f"[DEBUG] βœ… Image1 processed successfully")
1016
  except Exception as e:
1017
  print(f"[DEBUG] ❌ Error processing image1: {e}")
 
1020
  img2 = request.files['image2']
1021
  print(f"[DEBUG] πŸ–ΌοΈ Processing image2: {img2.filename}")
1022
  try:
1023
+ # Load image and convert to RGB to ensure it's fully loaded in memory
1024
+ image = Image.open(img2.stream).convert('RGB')
1025
+ images.append(image)
1026
  print(f"[DEBUG] βœ… Image2 processed successfully")
1027
  except Exception as e:
1028
  print(f"[DEBUG] ❌ Error processing image2: {e}")