Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -153,9 +153,9 @@ def get_topical_map(path):
|
|
153 |
def get_imgs_from_folder(image_files, zipfile):
|
154 |
|
155 |
# image file types
|
156 |
-
IMAGE_TYPES = ['jpg','jpeg','gif','bmp','png', 'jpe', 'heic']
|
157 |
# file types
|
158 |
-
FILE_TYPES = ['jpg','jpeg','gif','bmp','png', 'jpe', 'zip', 'mp4']
|
159 |
|
160 |
# gets all the image paths from the zipfile
|
161 |
zip = ZipFile(zipfile)
|
@@ -212,12 +212,17 @@ def get_seo_tags(image_path, topical_map, new_imgs, attempts=0, max_attempts=6):
|
|
212 |
heif_file.mode,
|
213 |
heif_file.stride,
|
214 |
)
|
|
|
|
|
|
|
|
|
|
|
215 |
else:
|
216 |
# Open other image types with PIL directly
|
217 |
image = Image.open(image_path)
|
218 |
-
|
219 |
-
# Convert image to RGB if it has an
|
220 |
-
if image.mode
|
221 |
image = image.convert('RGB')
|
222 |
|
223 |
# Use in-memory buffer for processing
|
|
|
153 |
def get_imgs_from_folder(image_files, zipfile):
|
154 |
|
155 |
# image file types
|
156 |
+
IMAGE_TYPES = ['jpg','jpeg','gif','bmp','png', 'jpe', 'heic', 'tiff', 'webp', 'heif', 'svg', 'raw', 'psd']
|
157 |
# file types
|
158 |
+
FILE_TYPES = ['jpg','jpeg','gif','bmp','png', 'jpe', 'zip', 'mp4', 'heic', 'tiff', 'webp', 'heif', 'svg', 'raw', 'psd']
|
159 |
|
160 |
# gets all the image paths from the zipfile
|
161 |
zip = ZipFile(zipfile)
|
|
|
212 |
heif_file.mode,
|
213 |
heif_file.stride,
|
214 |
)
|
215 |
+
elif image_path.lower().endswith('.gif'):
|
216 |
+
# Open GIF image
|
217 |
+
with Image.open(image_path) as img:
|
218 |
+
# Extract the first frame of the GIF
|
219 |
+
image = next(ImageSequence.Iterator(img)).convert('RGB')
|
220 |
else:
|
221 |
# Open other image types with PIL directly
|
222 |
image = Image.open(image_path)
|
223 |
+
|
224 |
+
# Convert image to RGB if it has an incompatible mode
|
225 |
+
if image.mode not in ['RGB', 'L']: # L is for grayscale
|
226 |
image = image.convert('RGB')
|
227 |
|
228 |
# Use in-memory buffer for processing
|