Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -291,15 +291,21 @@ def process_zip(zip_file, threshold):
|
|
| 291 |
with zipfile.ZipFile(zip_file.name, 'r') as zip_ref:
|
| 292 |
zip_ref.extractall(temp_dir)
|
| 293 |
|
| 294 |
-
all_files = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
image_files = [f for f in all_files if is_valid_image(f)]
|
| 296 |
results = process_images(image_files, threshold)
|
| 297 |
|
| 298 |
temp_file = NamedTemporaryFile(delete=False, suffix=".zip")
|
| 299 |
with zipfile.ZipFile(temp_file, "w") as zip_ref:
|
| 300 |
for image_name, text_no_impl, _ in results:
|
| 301 |
-
|
|
|
|
| 302 |
file.write(text_no_impl.encode())
|
|
|
|
| 303 |
temp_file.seek(0)
|
| 304 |
df = pd.DataFrame([(os.path.basename(f), t) for f, t, _ in results], columns=['Image', 'Tags'])
|
| 305 |
|
|
|
|
| 291 |
with zipfile.ZipFile(zip_file.name, 'r') as zip_ref:
|
| 292 |
zip_ref.extractall(temp_dir)
|
| 293 |
|
| 294 |
+
all_files = []
|
| 295 |
+
for root, _, files in os.walk(temp_dir):
|
| 296 |
+
for file in files:
|
| 297 |
+
all_files.append(os.path.join(root, file))
|
| 298 |
+
|
| 299 |
image_files = [f for f in all_files if is_valid_image(f)]
|
| 300 |
results = process_images(image_files, threshold)
|
| 301 |
|
| 302 |
temp_file = NamedTemporaryFile(delete=False, suffix=".zip")
|
| 303 |
with zipfile.ZipFile(temp_file, "w") as zip_ref:
|
| 304 |
for image_name, text_no_impl, _ in results:
|
| 305 |
+
txt_filename = ''.join(image_name.split('.')[:-1]) + ".txt"
|
| 306 |
+
with zip_ref.open(txt_filename, 'w') as file:
|
| 307 |
file.write(text_no_impl.encode())
|
| 308 |
+
|
| 309 |
temp_file.seek(0)
|
| 310 |
df = pd.DataFrame([(os.path.basename(f), t) for f, t, _ in results], columns=['Image', 'Tags'])
|
| 311 |
|