Spaces:
Sleeping
Sleeping
Fix: convert RGBA to RGB for SigLIP processor
Browse files
app.py
CHANGED
|
@@ -27,26 +27,15 @@ def encode(text: str) -> list:
|
|
| 27 |
return feats[0].tolist()
|
| 28 |
|
| 29 |
def encode_image(image) -> list:
|
| 30 |
-
print(f"encode_image called with type: {type(image)}")
|
| 31 |
if image is None:
|
| 32 |
raise gr.Error("No image provided")
|
| 33 |
-
# Gradio
|
| 34 |
-
if isinstance(image,
|
|
|
|
|
|
|
| 35 |
image = Image.open(image).convert("RGB")
|
| 36 |
-
|
| 37 |
-
# Gradio FileData dict: {"path": "/tmp/...", "url": "...", ...}
|
| 38 |
-
path = image.get("path") or image.get("url")
|
| 39 |
-
if path and path.startswith("data:"):
|
| 40 |
-
import base64, io
|
| 41 |
-
header, data = path.split(",", 1)
|
| 42 |
-
image = Image.open(io.BytesIO(base64.b64decode(data))).convert("RGB")
|
| 43 |
-
elif path:
|
| 44 |
-
image = Image.open(path).convert("RGB")
|
| 45 |
-
else:
|
| 46 |
-
raise gr.Error(f"Cannot parse image dict: {list(image.keys())}")
|
| 47 |
-
elif not isinstance(image, Image.Image):
|
| 48 |
raise gr.Error(f"Unexpected image type: {type(image)}")
|
| 49 |
-
print(f"Image size: {image.size}, mode: {image.mode}")
|
| 50 |
inputs = processor(images=[image], return_tensors="pt")
|
| 51 |
with torch.no_grad():
|
| 52 |
feats = model.get_image_features(pixel_values=inputs["pixel_values"])
|
|
|
|
| 27 |
return feats[0].tolist()
|
| 28 |
|
| 29 |
def encode_image(image) -> list:
|
|
|
|
| 30 |
if image is None:
|
| 31 |
raise gr.Error("No image provided")
|
| 32 |
+
# Gradio 6.x base64 shortcut returns RGBA — SigLIP needs RGB
|
| 33 |
+
if isinstance(image, Image.Image):
|
| 34 |
+
image = image.convert("RGB")
|
| 35 |
+
elif isinstance(image, str):
|
| 36 |
image = Image.open(image).convert("RGB")
|
| 37 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
raise gr.Error(f"Unexpected image type: {type(image)}")
|
|
|
|
| 39 |
inputs = processor(images=[image], return_tensors="pt")
|
| 40 |
with torch.no_grad():
|
| 41 |
feats = model.get_image_features(pixel_values=inputs["pixel_values"])
|