Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,8 +29,12 @@ def download_image(url: str, dest: str) -> None:
|
|
29 |
"""
|
30 |
logging.info(f"Downloading image from {url} to {dest}")
|
31 |
response = requests.get(url, stream=True)
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
del response
|
35 |
|
36 |
def download_image_by_image_id(image_id: str):
|
@@ -70,7 +74,10 @@ def download_batch_images(batch_id: str, workers: int = 2, progress=None):
|
|
70 |
with ZipFile(zip_filename, 'w') as zipf:
|
71 |
for image_id in image_ids:
|
72 |
img_path = os.path.join(batch_id, f"{image_id}.jpg")
|
73 |
-
|
|
|
|
|
|
|
74 |
|
75 |
if progress:
|
76 |
progress(1, desc=f"Completed {batch_id}")
|
|
|
29 |
"""
|
30 |
logging.info(f"Downloading image from {url} to {dest}")
|
31 |
response = requests.get(url, stream=True)
|
32 |
+
if response.status_code == 200:
|
33 |
+
with open(dest, "wb") as out_file:
|
34 |
+
shutil.copyfileobj(response.raw, out_file)
|
35 |
+
logging.info(f"Successfully downloaded image: {dest}")
|
36 |
+
else:
|
37 |
+
logging.error(f"Failed to download image from {url}. Status code: {response.status_code}")
|
38 |
del response
|
39 |
|
40 |
def download_image_by_image_id(image_id: str):
|
|
|
74 |
with ZipFile(zip_filename, 'w') as zipf:
|
75 |
for image_id in image_ids:
|
76 |
img_path = os.path.join(batch_id, f"{image_id}.jpg")
|
77 |
+
if os.path.exists(img_path):
|
78 |
+
zipf.write(img_path, arcname=os.path.basename(img_path))
|
79 |
+
else:
|
80 |
+
logging.warning(f"Image {img_path} does not exist and will not be zipped.")
|
81 |
|
82 |
if progress:
|
83 |
progress(1, desc=f"Completed {batch_id}")
|