Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files- remove_background.py +14 -11
remove_background.py
CHANGED
|
@@ -7,16 +7,19 @@ output_folder = 'Output_images' # Folder where images without background will b
|
|
| 7 |
|
| 8 |
os.makedirs(output_folder, exist_ok=True)
|
| 9 |
|
| 10 |
-
for
|
| 11 |
-
|
| 12 |
-
input_path = os.path.join(input_folder, filename)
|
| 13 |
-
output_path = os.path.join(output_folder, filename)
|
| 14 |
-
|
| 15 |
-
with open(input_path, 'rb') as i:
|
| 16 |
-
input_data = i.read()
|
| 17 |
-
output_data = remove(input_data)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
os.makedirs(output_folder, exist_ok=True)
|
| 9 |
|
| 10 |
+
image_files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
| 11 |
+
total_images = len(image_files)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
for index, filename in enumerate(image_files):
|
| 14 |
+
print(f"Processing image {index + 1}/{total_images}: {filename}")
|
| 15 |
+
input_path = os.path.join(input_folder, filename)
|
| 16 |
+
output_path = os.path.join(output_folder, filename)
|
| 17 |
+
|
| 18 |
+
with open(input_path, 'rb') as i:
|
| 19 |
+
input_data = i.read()
|
| 20 |
+
output_data = remove(input_data)
|
| 21 |
|
| 22 |
+
with open(output_path, 'wb') as o:
|
| 23 |
+
o.write(output_data)
|
| 24 |
+
|
| 25 |
+
print(f'\nAll {total_images} images processed and saved to {output_folder}')
|