user-agent commited on
Commit
0623b90
·
verified ·
1 Parent(s): 3d3a8e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -126,9 +126,12 @@ def load_image_from_data_url(data_url: str) -> Image.Image:
126
  """Load image from base64 data URL"""
127
  if data_url.startswith("data:image/"):
128
  # Extract base64 data after the comma
129
- header, encoded = data_url.split(",", 1)
130
- image_data = base64.b64decode(encoded)
131
- return Image.open(BytesIO(image_data))
 
 
 
132
  else:
133
  # Regular URL, use existing load_img function
134
  return load_img(data_url, output_type="pil")
 
126
  """Load image from base64 data URL"""
127
  if data_url.startswith("data:image/"):
128
  # Extract base64 data after the comma
129
+ if "," in data_url:
130
+ header, encoded = data_url.split(",", 1)
131
+ image_data = base64.b64decode(encoded)
132
+ return Image.open(BytesIO(image_data))
133
+ else:
134
+ raise ValueError(f"Invalid data URL format: {data_url[:50]}...")
135
  else:
136
  # Regular URL, use existing load_img function
137
  return load_img(data_url, output_type="pil")