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