Spaces:
Sleeping
Sleeping
Romain Graux
commited on
Commit
·
1a5c8e7
1
Parent(s):
25a8030
Add progress per image
Browse files
app.py
CHANGED
@@ -56,14 +56,23 @@ def inf(img, n_species, threshold, architecture):
|
|
56 |
return img, results
|
57 |
|
58 |
|
59 |
-
def batch_fn(
|
60 |
-
|
|
|
|
|
61 |
block_state = {}
|
62 |
if not files:
|
63 |
raise ValueError("No files were uploaded")
|
64 |
|
65 |
gallery = []
|
66 |
-
for file in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
error_physical_metadata = None
|
68 |
try:
|
69 |
physical_metadata = extract_physical_metadata(file.name)
|
@@ -72,11 +81,13 @@ def batch_fn(files, n_species, threshold, architecture, block_state, progress=gr
|
|
72 |
except Exception as e:
|
73 |
error_physical_metadata = e
|
74 |
physical_metadata = None
|
75 |
-
|
76 |
original_file_name = file.name.split("/")[-1]
|
|
|
77 |
img, results = inf(file.name, n_species, threshold, architecture)
|
|
|
78 |
mask = segment_image(file.name)
|
79 |
gallery.append((img, original_file_name))
|
|
|
80 |
|
81 |
if physical_metadata is not None:
|
82 |
factor = 1.0 - np.mean(mask)
|
|
|
56 |
return img, results
|
57 |
|
58 |
|
59 |
+
def batch_fn(
|
60 |
+
files, n_species, threshold, architecture, block_state, progress=gr.Progress()
|
61 |
+
):
|
62 |
+
progress(0, desc="Starting...")
|
63 |
block_state = {}
|
64 |
if not files:
|
65 |
raise ValueError("No files were uploaded")
|
66 |
|
67 |
gallery = []
|
68 |
+
for file_idx, file in enumerate(files):
|
69 |
+
base_progress = file_idx / len(files)
|
70 |
+
display_progress = lambda value, text=None: progress(
|
71 |
+
base_progress + (1 / len(files)) * value,
|
72 |
+
desc=f"Processing image {file_idx+1}/{len(files)}{' - ' + text if text else '...'}",
|
73 |
+
)
|
74 |
+
display_progress(0)
|
75 |
+
display_progress(0.1, "Extracting metadata...")
|
76 |
error_physical_metadata = None
|
77 |
try:
|
78 |
physical_metadata = extract_physical_metadata(file.name)
|
|
|
81 |
except Exception as e:
|
82 |
error_physical_metadata = e
|
83 |
physical_metadata = None
|
|
|
84 |
original_file_name = file.name.split("/")[-1]
|
85 |
+
display_progress(0.2, "Inference...")
|
86 |
img, results = inf(file.name, n_species, threshold, architecture)
|
87 |
+
display_progress(0.8, "Segmentation...")
|
88 |
mask = segment_image(file.name)
|
89 |
gallery.append((img, original_file_name))
|
90 |
+
display_progress(1, "Done")
|
91 |
|
92 |
if physical_metadata is not None:
|
93 |
factor = 1.0 - np.mean(mask)
|