Spaces:
Sleeping
Sleeping
Remove dead code
Browse files62 unmodified lines63646566666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071086962 unmodified lines
return temp_path
except Exception as e: except Exception: # Clean up temp file if creation failed Path(temp_path).unlink(missing_ok=True) print(f"Error creating zip file: {e}") return None
# Create a temporary file temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".zip") temp_path = temp_file.name temp_file.close()
try: with zipfile.ZipFile(temp_path, "w", zipfile.ZIP_DEFLATED) as zip_file: for image_data in dataset.images: image_path = image_data["path"] label = image_data["label"]
try: # Add the image file to zip with open(image_path, "rb") as img_file: zip_file.writestr( f"images/{Path(image_path).name}", img_file.read() )
# Create and add the text file with the same base name base_name = Path(image_path).stem text_filename = f"labels/{base_name}.txt" zip_file.writestr(text_filename, label.encode("utf-8"))
except FileNotFoundError: # Skip if image file doesn't exist continue except Exception as e: # Log error but continue with other files print(f"Error processing {image_path}: {e}") continue
return temp_path
except Exception as e: # Clean up temp file if creation failed Path(temp_path).unlink(missing_ok=True) print(f"Error creating zip file: {e}") return Nonepackager.py+1-41