birdnet-analyzer 2.0.0__py3-none-any.whl → 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- birdnet_analyzer/__init__.py +9 -8
- birdnet_analyzer/analyze/__init__.py +5 -5
- birdnet_analyzer/analyze/__main__.py +3 -4
- birdnet_analyzer/analyze/cli.py +25 -25
- birdnet_analyzer/analyze/core.py +241 -245
- birdnet_analyzer/analyze/utils.py +692 -701
- birdnet_analyzer/audio.py +368 -372
- birdnet_analyzer/cli.py +709 -707
- birdnet_analyzer/config.py +242 -242
- birdnet_analyzer/eBird_taxonomy_codes_2021E.json +25279 -25279
- birdnet_analyzer/embeddings/__init__.py +3 -4
- birdnet_analyzer/embeddings/__main__.py +3 -3
- birdnet_analyzer/embeddings/cli.py +12 -13
- birdnet_analyzer/embeddings/core.py +69 -70
- birdnet_analyzer/embeddings/utils.py +179 -193
- birdnet_analyzer/evaluation/__init__.py +196 -195
- birdnet_analyzer/evaluation/__main__.py +3 -3
- birdnet_analyzer/evaluation/assessment/__init__.py +0 -0
- birdnet_analyzer/evaluation/assessment/metrics.py +388 -0
- birdnet_analyzer/evaluation/assessment/performance_assessor.py +409 -0
- birdnet_analyzer/evaluation/assessment/plotting.py +379 -0
- birdnet_analyzer/evaluation/preprocessing/__init__.py +0 -0
- birdnet_analyzer/evaluation/preprocessing/data_processor.py +631 -0
- birdnet_analyzer/evaluation/preprocessing/utils.py +98 -0
- birdnet_analyzer/gui/__init__.py +19 -23
- birdnet_analyzer/gui/__main__.py +3 -3
- birdnet_analyzer/gui/analysis.py +175 -174
- birdnet_analyzer/gui/assets/arrow_down.svg +4 -4
- birdnet_analyzer/gui/assets/arrow_left.svg +4 -4
- birdnet_analyzer/gui/assets/arrow_right.svg +4 -4
- birdnet_analyzer/gui/assets/arrow_up.svg +4 -4
- birdnet_analyzer/gui/assets/gui.css +28 -28
- birdnet_analyzer/gui/assets/gui.js +93 -93
- birdnet_analyzer/gui/embeddings.py +619 -620
- birdnet_analyzer/gui/evaluation.py +795 -813
- birdnet_analyzer/gui/localization.py +75 -68
- birdnet_analyzer/gui/multi_file.py +245 -246
- birdnet_analyzer/gui/review.py +519 -527
- birdnet_analyzer/gui/segments.py +191 -191
- birdnet_analyzer/gui/settings.py +128 -129
- birdnet_analyzer/gui/single_file.py +267 -269
- birdnet_analyzer/gui/species.py +95 -95
- birdnet_analyzer/gui/train.py +696 -698
- birdnet_analyzer/gui/utils.py +810 -808
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_af.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ar.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_bg.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ca.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_cs.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_da.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_de.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_el.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_en_uk.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_es.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_fi.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_fr.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_he.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_hr.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_hu.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_in.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_is.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_it.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ja.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ko.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_lt.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ml.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_nl.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_no.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pl.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pt_BR.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_pt_PT.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ro.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_ru.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sk.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sl.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sr.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_sv.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_th.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_tr.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_uk.txt +6522 -6522
- birdnet_analyzer/labels/V2.4/BirdNET_GLOBAL_6K_V2.4_Labels_zh.txt +6522 -6522
- birdnet_analyzer/lang/de.json +334 -334
- birdnet_analyzer/lang/en.json +334 -334
- birdnet_analyzer/lang/fi.json +334 -334
- birdnet_analyzer/lang/fr.json +334 -334
- birdnet_analyzer/lang/id.json +334 -334
- birdnet_analyzer/lang/pt-br.json +334 -334
- birdnet_analyzer/lang/ru.json +334 -334
- birdnet_analyzer/lang/se.json +334 -334
- birdnet_analyzer/lang/tlh.json +334 -334
- birdnet_analyzer/lang/zh_TW.json +334 -334
- birdnet_analyzer/model.py +1212 -1243
- birdnet_analyzer/playground.py +5 -0
- birdnet_analyzer/search/__init__.py +3 -3
- birdnet_analyzer/search/__main__.py +3 -3
- birdnet_analyzer/search/cli.py +11 -12
- birdnet_analyzer/search/core.py +78 -78
- birdnet_analyzer/search/utils.py +107 -111
- birdnet_analyzer/segments/__init__.py +3 -3
- birdnet_analyzer/segments/__main__.py +3 -3
- birdnet_analyzer/segments/cli.py +13 -14
- birdnet_analyzer/segments/core.py +81 -78
- birdnet_analyzer/segments/utils.py +383 -394
- birdnet_analyzer/species/__init__.py +3 -3
- birdnet_analyzer/species/__main__.py +3 -3
- birdnet_analyzer/species/cli.py +13 -14
- birdnet_analyzer/species/core.py +35 -35
- birdnet_analyzer/species/utils.py +74 -75
- birdnet_analyzer/train/__init__.py +3 -3
- birdnet_analyzer/train/__main__.py +3 -3
- birdnet_analyzer/train/cli.py +13 -14
- birdnet_analyzer/train/core.py +113 -113
- birdnet_analyzer/train/utils.py +877 -847
- birdnet_analyzer/translate.py +133 -104
- birdnet_analyzer/utils.py +426 -419
- {birdnet_analyzer-2.0.0.dist-info → birdnet_analyzer-2.0.1.dist-info}/METADATA +137 -129
- birdnet_analyzer-2.0.1.dist-info/RECORD +125 -0
- {birdnet_analyzer-2.0.0.dist-info → birdnet_analyzer-2.0.1.dist-info}/WHEEL +1 -1
- {birdnet_analyzer-2.0.0.dist-info → birdnet_analyzer-2.0.1.dist-info}/licenses/LICENSE +18 -18
- birdnet_analyzer-2.0.0.dist-info/RECORD +0 -117
- {birdnet_analyzer-2.0.0.dist-info → birdnet_analyzer-2.0.1.dist-info}/entry_points.txt +0 -0
- {birdnet_analyzer-2.0.0.dist-info → birdnet_analyzer-2.0.1.dist-info}/top_level.txt +0 -0
@@ -1,269 +1,267 @@
|
|
1
|
-
import os
|
2
|
-
|
3
|
-
import gradio as gr
|
4
|
-
|
5
|
-
import birdnet_analyzer.
|
6
|
-
import birdnet_analyzer.
|
7
|
-
import birdnet_analyzer.gui.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
import
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
data =
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
"",
|
158
|
-
loc.localize("single-tab-output-header-
|
159
|
-
loc.localize("single-tab-output-header-
|
160
|
-
loc.localize("single-tab-output-header-
|
161
|
-
loc.localize("single-tab-output-header-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
i["path"],
|
173
|
-
gr.
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
hours
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
if __name__ == "__main__":
|
269
|
-
gu.open_window(build_single_analysis_tab)
|
1
|
+
import os
|
2
|
+
|
3
|
+
import gradio as gr
|
4
|
+
|
5
|
+
import birdnet_analyzer.config as cfg
|
6
|
+
import birdnet_analyzer.gui.localization as loc
|
7
|
+
import birdnet_analyzer.gui.utils as gu
|
8
|
+
from birdnet_analyzer import audio, utils
|
9
|
+
|
10
|
+
|
11
|
+
@gu.gui_runtime_error_handler
|
12
|
+
def run_single_file_analysis(
|
13
|
+
input_path,
|
14
|
+
use_top_n,
|
15
|
+
top_n,
|
16
|
+
confidence,
|
17
|
+
sensitivity,
|
18
|
+
overlap,
|
19
|
+
merge_consecutive,
|
20
|
+
audio_speed,
|
21
|
+
fmin,
|
22
|
+
fmax,
|
23
|
+
species_list_choice,
|
24
|
+
species_list_file,
|
25
|
+
lat,
|
26
|
+
lon,
|
27
|
+
week,
|
28
|
+
use_yearlong,
|
29
|
+
sf_thresh,
|
30
|
+
custom_classifier_file,
|
31
|
+
locale,
|
32
|
+
):
|
33
|
+
import csv
|
34
|
+
from datetime import timedelta
|
35
|
+
|
36
|
+
from birdnet_analyzer.gui.analysis import run_analysis
|
37
|
+
|
38
|
+
if species_list_choice == gu._CUSTOM_SPECIES:
|
39
|
+
gu.validate(species_list_file, loc.localize("validation-no-species-list-selected"))
|
40
|
+
|
41
|
+
gu.validate(input_path, loc.localize("validation-no-file-selected"))
|
42
|
+
|
43
|
+
if fmin is None or fmax is None or fmin < cfg.SIG_FMIN or fmax > cfg.SIG_FMAX or fmin > fmax:
|
44
|
+
raise gr.Error(f"{loc.localize('validation-no-valid-frequency')} [{cfg.SIG_FMIN}, {cfg.SIG_FMAX}]")
|
45
|
+
|
46
|
+
result_filepath = run_analysis(
|
47
|
+
input_path,
|
48
|
+
None,
|
49
|
+
use_top_n,
|
50
|
+
top_n,
|
51
|
+
confidence,
|
52
|
+
sensitivity,
|
53
|
+
overlap,
|
54
|
+
merge_consecutive,
|
55
|
+
audio_speed,
|
56
|
+
fmin,
|
57
|
+
fmax,
|
58
|
+
species_list_choice,
|
59
|
+
species_list_file,
|
60
|
+
lat,
|
61
|
+
lon,
|
62
|
+
week,
|
63
|
+
use_yearlong,
|
64
|
+
sf_thresh,
|
65
|
+
custom_classifier_file,
|
66
|
+
"csv",
|
67
|
+
None,
|
68
|
+
locale if locale else "en",
|
69
|
+
1,
|
70
|
+
4,
|
71
|
+
None,
|
72
|
+
skip_existing=False,
|
73
|
+
save_params=False,
|
74
|
+
progress=None,
|
75
|
+
)
|
76
|
+
|
77
|
+
if not result_filepath:
|
78
|
+
raise gr.Error(loc.localize("single-tab-analyze-file-error"))
|
79
|
+
|
80
|
+
# read the result file to return the data to be displayed.
|
81
|
+
with open(result_filepath, encoding="utf-8") as f:
|
82
|
+
reader = csv.reader(f)
|
83
|
+
data = list(reader)
|
84
|
+
data = [lc[0:-1] for lc in data[1:]] # remove last column (file path) and first row (header)
|
85
|
+
|
86
|
+
for row in data:
|
87
|
+
for col_idx in range(2):
|
88
|
+
seconds = float(row[col_idx])
|
89
|
+
time_str = str(timedelta(seconds=seconds))
|
90
|
+
|
91
|
+
if "." in time_str:
|
92
|
+
time_str = time_str[: time_str.index(".") + 2]
|
93
|
+
|
94
|
+
row[col_idx] = time_str
|
95
|
+
row.insert(0, "▶")
|
96
|
+
|
97
|
+
return data, gr.update(visible=True), result_filepath
|
98
|
+
|
99
|
+
|
100
|
+
def build_single_analysis_tab():
|
101
|
+
with gr.Tab(loc.localize("single-tab-title")):
|
102
|
+
audio_input = gr.Audio(type="filepath", label=loc.localize("single-audio-label"), sources=["upload"])
|
103
|
+
|
104
|
+
with gr.Group():
|
105
|
+
spectogram_output = gr.Plot(
|
106
|
+
label=loc.localize("review-tab-spectrogram-plot-label"), visible=False, show_label=False
|
107
|
+
)
|
108
|
+
generate_spectrogram_cb = gr.Checkbox(
|
109
|
+
value=True,
|
110
|
+
label=loc.localize("single-tab-spectrogram-checkbox-label"),
|
111
|
+
info=loc.localize("single-tab-spectrogram-checkbox-info"),
|
112
|
+
)
|
113
|
+
audio_path_state = gr.State()
|
114
|
+
table_path_state = gr.State()
|
115
|
+
|
116
|
+
(
|
117
|
+
use_top_n,
|
118
|
+
top_n_input,
|
119
|
+
confidence_slider,
|
120
|
+
sensitivity_slider,
|
121
|
+
overlap_slider,
|
122
|
+
merge_consecutive_slider,
|
123
|
+
audio_speed_slider,
|
124
|
+
fmin_number,
|
125
|
+
fmax_number,
|
126
|
+
) = gu.sample_sliders(False)
|
127
|
+
|
128
|
+
(
|
129
|
+
species_list_radio,
|
130
|
+
species_file_input,
|
131
|
+
lat_number,
|
132
|
+
lon_number,
|
133
|
+
week_number,
|
134
|
+
sf_thresh_number,
|
135
|
+
yearlong_checkbox,
|
136
|
+
selected_classifier_state,
|
137
|
+
map_plot,
|
138
|
+
) = gu.species_lists(False)
|
139
|
+
locale_radio = gu.locale()
|
140
|
+
|
141
|
+
single_file_analyze = gr.Button(
|
142
|
+
loc.localize("analyze-start-button-label"), variant="huggingface", interactive=False
|
143
|
+
)
|
144
|
+
|
145
|
+
with gr.Row(visible=False) as action_row:
|
146
|
+
table_download_button = gr.Button(
|
147
|
+
loc.localize("single-tab-download-button-label"),
|
148
|
+
)
|
149
|
+
segment_audio = gr.Audio(
|
150
|
+
autoplay=True, type="numpy", show_download_button=True, show_label=False, editable=False, visible=False
|
151
|
+
)
|
152
|
+
|
153
|
+
output_dataframe = gr.Dataframe(
|
154
|
+
type="pandas",
|
155
|
+
headers=[
|
156
|
+
"",
|
157
|
+
loc.localize("single-tab-output-header-start"),
|
158
|
+
loc.localize("single-tab-output-header-end"),
|
159
|
+
loc.localize("single-tab-output-header-sci-name"),
|
160
|
+
loc.localize("single-tab-output-header-common-name"),
|
161
|
+
loc.localize("single-tab-output-header-confidence"),
|
162
|
+
],
|
163
|
+
elem_id="single-file-output",
|
164
|
+
interactive=False,
|
165
|
+
)
|
166
|
+
|
167
|
+
def get_audio_path(i, generate_spectrogram):
|
168
|
+
if i:
|
169
|
+
try:
|
170
|
+
return (
|
171
|
+
i["path"],
|
172
|
+
gr.Audio(label=os.path.basename(i["path"])),
|
173
|
+
gr.Plot(visible=True, value=utils.spectrogram_from_file(i["path"], fig_size=(20, 4)))
|
174
|
+
if generate_spectrogram
|
175
|
+
else gr.Plot(visible=False),
|
176
|
+
gr.Button(interactive=True),
|
177
|
+
)
|
178
|
+
except Exception as e:
|
179
|
+
raise gr.Error(loc.localize("single-tab-generate-spectrogram-error")) from e
|
180
|
+
else:
|
181
|
+
return None, None, gr.Plot(visible=False), gr.update(interactive=False)
|
182
|
+
|
183
|
+
def try_generate_spectrogram(audio_path, generate_spectrogram):
|
184
|
+
if audio_path and generate_spectrogram:
|
185
|
+
try:
|
186
|
+
return gr.Plot(
|
187
|
+
visible=True, value=utils.spectrogram_from_file(audio_path["path"], fig_size=(20, 4))
|
188
|
+
)
|
189
|
+
except Exception as e:
|
190
|
+
raise gr.Error(loc.localize("single-tab-generate-spectrogram-error")) from e
|
191
|
+
else:
|
192
|
+
return gr.Plot()
|
193
|
+
|
194
|
+
generate_spectrogram_cb.change(
|
195
|
+
try_generate_spectrogram,
|
196
|
+
inputs=[audio_input, generate_spectrogram_cb],
|
197
|
+
outputs=spectogram_output,
|
198
|
+
preprocess=False,
|
199
|
+
)
|
200
|
+
|
201
|
+
audio_input.change(
|
202
|
+
get_audio_path,
|
203
|
+
inputs=[audio_input, generate_spectrogram_cb],
|
204
|
+
outputs=[audio_path_state, audio_input, spectogram_output, single_file_analyze],
|
205
|
+
preprocess=False,
|
206
|
+
)
|
207
|
+
|
208
|
+
inputs = [
|
209
|
+
audio_path_state,
|
210
|
+
use_top_n,
|
211
|
+
top_n_input,
|
212
|
+
confidence_slider,
|
213
|
+
sensitivity_slider,
|
214
|
+
overlap_slider,
|
215
|
+
merge_consecutive_slider,
|
216
|
+
audio_speed_slider,
|
217
|
+
fmin_number,
|
218
|
+
fmax_number,
|
219
|
+
species_list_radio,
|
220
|
+
species_file_input,
|
221
|
+
lat_number,
|
222
|
+
lon_number,
|
223
|
+
week_number,
|
224
|
+
yearlong_checkbox,
|
225
|
+
sf_thresh_number,
|
226
|
+
selected_classifier_state,
|
227
|
+
locale_radio,
|
228
|
+
]
|
229
|
+
|
230
|
+
def time_to_seconds(time_str):
|
231
|
+
try:
|
232
|
+
hours, minutes, seconds = time_str.split(":")
|
233
|
+
return int(hours) * 3600 + int(minutes) * 60 + float(seconds)
|
234
|
+
|
235
|
+
except ValueError as e:
|
236
|
+
raise ValueError("Input must be in the format hh:mm:ss or hh:mm:ss.ssssss with numeric values.") from e
|
237
|
+
|
238
|
+
def get_selected_audio(evt: gr.SelectData, audio_path):
|
239
|
+
if evt.index[1] == 0 and evt.row_value[1] and evt.row_value[2]:
|
240
|
+
start = time_to_seconds(evt.row_value[1])
|
241
|
+
end = time_to_seconds(evt.row_value[2])
|
242
|
+
|
243
|
+
data, sr = audio.open_audio_file(audio_path, offset=start, duration=end - start)
|
244
|
+
return gr.update(visible=True, value=(sr, data))
|
245
|
+
|
246
|
+
return gr.update()
|
247
|
+
|
248
|
+
def download_table(filepath):
|
249
|
+
if filepath:
|
250
|
+
ext = os.path.splitext(filepath)[1]
|
251
|
+
gu.save_file_dialog(
|
252
|
+
state_key="single-file-table",
|
253
|
+
default_filename=os.path.basename(filepath),
|
254
|
+
filetypes=(f"{ext[1:]} (*{ext})",),
|
255
|
+
)
|
256
|
+
|
257
|
+
output_dataframe.select(get_selected_audio, inputs=audio_path_state, outputs=segment_audio)
|
258
|
+
single_file_analyze.click(
|
259
|
+
run_single_file_analysis, inputs=inputs, outputs=[output_dataframe, action_row, table_path_state]
|
260
|
+
)
|
261
|
+
table_download_button.click(download_table, inputs=table_path_state)
|
262
|
+
|
263
|
+
return lat_number, lon_number, map_plot
|
264
|
+
|
265
|
+
|
266
|
+
if __name__ == "__main__":
|
267
|
+
gu.open_window(build_single_analysis_tab)
|