Update app.py
Browse files
app.py
CHANGED
|
@@ -3442,20 +3442,36 @@ SPRITE_DIR/"Zebra.sprite3"/"f3e322a25b9f79801066056de6f33fb1.png"
|
|
| 3442 |
# # ============================== #
|
| 3443 |
# # EMBED SPRITE IMAGES #
|
| 3444 |
# # ============================== #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3445 |
sprite_features = []
|
| 3446 |
-
for
|
| 3447 |
-
|
|
|
|
| 3448 |
b64 = b64.split(",", 1)[1]
|
| 3449 |
|
| 3450 |
img_bytes = base64.b64decode(b64)
|
| 3451 |
pil_img = Image.open(BytesIO(img_bytes)).convert("RGB")
|
| 3452 |
|
| 3453 |
-
# optional re-encode to PNG for CLIP
|
| 3454 |
buf = BytesIO()
|
| 3455 |
pil_img.save(buf, format="PNG")
|
| 3456 |
buf.seek(0)
|
| 3457 |
|
| 3458 |
-
feats = clip_embd.embed_image([buf])[0]
|
| 3459 |
sprite_features.append(feats)
|
| 3460 |
|
| 3461 |
# sprite_matrix = np.array(sprite_features, dtype=np.float32)
|
|
|
|
| 3442 |
# # ============================== #
|
| 3443 |
# # EMBED SPRITE IMAGES #
|
| 3444 |
# # ============================== #
|
| 3445 |
+
# sprite_features = []
|
| 3446 |
+
# for b64 in sprite_base64:
|
| 3447 |
+
# if "," in b64: # strip data URI prefix if present
|
| 3448 |
+
# b64 = b64.split(",", 1)[1]
|
| 3449 |
+
|
| 3450 |
+
# img_bytes = base64.b64decode(b64)
|
| 3451 |
+
# pil_img = Image.open(BytesIO(img_bytes)).convert("RGB")
|
| 3452 |
+
|
| 3453 |
+
# # optional re-encode to PNG for CLIP
|
| 3454 |
+
# buf = BytesIO()
|
| 3455 |
+
# pil_img.save(buf, format="PNG")
|
| 3456 |
+
# buf.seek(0)
|
| 3457 |
+
|
| 3458 |
+
# feats = clip_embd.embed_image([buf])[0] # extract CLIP embedding
|
| 3459 |
+
# sprite_features.append(feats)
|
| 3460 |
+
|
| 3461 |
sprite_features = []
|
| 3462 |
+
for sprite in sprites_data.values(): # assuming dict like {"Sprite 1": {...}, ...}
|
| 3463 |
+
b64 = sprite["base64"]
|
| 3464 |
+
if "," in b64:
|
| 3465 |
b64 = b64.split(",", 1)[1]
|
| 3466 |
|
| 3467 |
img_bytes = base64.b64decode(b64)
|
| 3468 |
pil_img = Image.open(BytesIO(img_bytes)).convert("RGB")
|
| 3469 |
|
|
|
|
| 3470 |
buf = BytesIO()
|
| 3471 |
pil_img.save(buf, format="PNG")
|
| 3472 |
buf.seek(0)
|
| 3473 |
|
| 3474 |
+
feats = clip_embd.embed_image([buf])[0]
|
| 3475 |
sprite_features.append(feats)
|
| 3476 |
|
| 3477 |
# sprite_matrix = np.array(sprite_features, dtype=np.float32)
|