Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update similarity.py
Browse files- similarity.py +8 -7
similarity.py
CHANGED
@@ -137,13 +137,7 @@ def load_image_url(source, assetCode, contentType=None, ffmpeg_path='ffmpeg', fr
|
|
137 |
try:
|
138 |
img_bytes = base64.b64decode(source)
|
139 |
|
140 |
-
if contentType and contentType.startswith('
|
141 |
-
print(f"[INFO] Base64 de {assetCode} identificado como imagem")
|
142 |
-
img = Image.open(BytesIO(img_bytes))
|
143 |
-
img = np.array(img)
|
144 |
-
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
145 |
-
return img
|
146 |
-
else:
|
147 |
print(f"[INFO] Base64 de {assetCode} identificado como vídeo")
|
148 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_video:
|
149 |
temp_video.write(img_bytes)
|
@@ -152,6 +146,13 @@ def load_image_url(source, assetCode, contentType=None, ffmpeg_path='ffmpeg', fr
|
|
152 |
frame = extract_frame_from_video(temp_video_path, frame_time)
|
153 |
os.remove(temp_video_path)
|
154 |
return frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
except Exception as e:
|
157 |
print(f"[ERRO] Falha ao processar base64 de {assetCode}: {e}")
|
|
|
137 |
try:
|
138 |
img_bytes = base64.b64decode(source)
|
139 |
|
140 |
+
if contentType and contentType.startswith('video'):
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
print(f"[INFO] Base64 de {assetCode} identificado como vídeo")
|
142 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_video:
|
143 |
temp_video.write(img_bytes)
|
|
|
146 |
frame = extract_frame_from_video(temp_video_path, frame_time)
|
147 |
os.remove(temp_video_path)
|
148 |
return frame
|
149 |
+
else:
|
150 |
+
print(f"[INFO] Base64 de {assetCode} identificado como imagem")
|
151 |
+
img = Image.open(BytesIO(img_bytes))
|
152 |
+
img = np.array(img)
|
153 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
154 |
+
return img
|
155 |
+
|
156 |
|
157 |
except Exception as e:
|
158 |
print(f"[ERRO] Falha ao processar base64 de {assetCode}: {e}")
|