Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,23 +39,23 @@ def wait_for_image_with_prefix(folder, prefix):
|
|
| 39 |
time.sleep(1)
|
| 40 |
return initial_size == os.path.getsize(file_path)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
|
| 61 |
def delete_image_file(file_path):
|
|
|
|
| 39 |
time.sleep(1)
|
| 40 |
return initial_size == os.path.getsize(file_path)
|
| 41 |
|
| 42 |
+
|
| 43 |
+
files = os.listdir(folder)
|
| 44 |
+
image_files = [f for f in files if f.lower().startswith(prefix.lower()) and
|
| 45 |
+
f.lower().endswith(('.png', '.jpg', '.jpeg'))]
|
| 46 |
+
|
| 47 |
+
if image_files:
|
| 48 |
+
# Sort by modification time to get the latest file
|
| 49 |
+
image_files.sort(key=lambda x: os.path.getmtime(os.path.join(folder, x)), reverse=True)
|
| 50 |
+
latest_image = os.path.join(folder, image_files[0])
|
| 51 |
+
|
| 52 |
+
if is_file_ready(latest_image):
|
| 53 |
+
# Wait a bit more to ensure the file is completely written
|
| 54 |
+
time.sleep(3)
|
| 55 |
+
return latest_image
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
return None
|
| 59 |
|
| 60 |
|
| 61 |
def delete_image_file(file_path):
|