Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -240,19 +240,27 @@ df_combined["chaos_score"] = np.log1p(df_combined.get("diag_srl_gamma", 0)) / (d
|
|
240 |
def resolve_audio_path(row: pd.Series) -> str:
|
241 |
"""
|
242 |
Intelligently reconstructs the full path to an audio file
|
243 |
-
based on the
|
|
|
|
|
|
|
244 |
"""
|
245 |
basename = str(row.get("filepath", ""))
|
246 |
source = row.get("source", "")
|
247 |
label = row.get("label", "")
|
248 |
|
249 |
-
# For "Dog" data, the structure is:
|
250 |
if source == "Dog":
|
251 |
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, label, basename)
|
252 |
if os.path.exists(expected_path):
|
253 |
return expected_path
|
|
|
|
|
|
|
|
|
|
|
254 |
|
255 |
-
# For "Human" data,
|
256 |
elif source == "Human":
|
257 |
if os.path.isdir(HUMAN_AUDIO_BASE_PATH):
|
258 |
for actor_folder in os.listdir(HUMAN_AUDIO_BASE_PATH):
|
@@ -260,12 +268,28 @@ def resolve_audio_path(row: pd.Series) -> str:
|
|
260 |
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, actor_folder, basename)
|
261 |
if os.path.exists(expected_path):
|
262 |
return expected_path
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
# Fallback for dummy data or other cases
|
265 |
if os.path.exists(basename):
|
266 |
return basename
|
267 |
|
268 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
return basename
|
270 |
|
271 |
def get_cmt_data(filepath: str, lens: str):
|
@@ -596,17 +620,20 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) a
|
|
596 |
)
|
597 |
|
598 |
# Primary file selection (filtered by species)
|
|
|
|
|
|
|
599 |
primary_dropdown = gr.Dropdown(
|
600 |
label="Primary Audio File",
|
601 |
-
choices=
|
602 |
-
value=
|
603 |
)
|
604 |
|
605 |
# Automatically found neighbor (from opposite species)
|
606 |
neighbor_dropdown = gr.Dropdown(
|
607 |
label="Auto-Found Cross-Species Neighbor",
|
608 |
-
choices=
|
609 |
-
value=
|
610 |
interactive=True # Allow manual override
|
611 |
)
|
612 |
|
@@ -754,12 +781,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) a
|
|
754 |
inputs=cross_species_inputs,
|
755 |
outputs=cross_species_outputs)
|
756 |
|
757 |
-
# Initialize on load
|
758 |
-
demo.load(lambda: update_dropdowns_on_species_change("Dog"),
|
759 |
-
outputs=[primary_dropdown, neighbor_dropdown])
|
760 |
-
demo.load(update_cross_species_view,
|
761 |
-
inputs=cross_species_inputs,
|
762 |
-
outputs=cross_species_outputs)
|
763 |
|
764 |
if __name__ == "__main__":
|
765 |
demo.launch(share=True, debug=True)
|
|
|
240 |
def resolve_audio_path(row: pd.Series) -> str:
|
241 |
"""
|
242 |
Intelligently reconstructs the full path to an audio file
|
243 |
+
based on the actual file structure patterns.
|
244 |
+
|
245 |
+
Dog files: combined/{label}/{filename} e.g., combined/bark/bark_bark (1).wav
|
246 |
+
Human files: human/Actor_XX/{filename} e.g., human/Actor_01/03-01-01-01-01-01-01.wav
|
247 |
"""
|
248 |
basename = str(row.get("filepath", ""))
|
249 |
source = row.get("source", "")
|
250 |
label = row.get("label", "")
|
251 |
|
252 |
+
# For "Dog" data, the structure is: combined/{label}/{filename}
|
253 |
if source == "Dog":
|
254 |
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, label, basename)
|
255 |
if os.path.exists(expected_path):
|
256 |
return expected_path
|
257 |
+
|
258 |
+
# Try without subdirectory in case files are flat
|
259 |
+
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, basename)
|
260 |
+
if os.path.exists(expected_path):
|
261 |
+
return expected_path
|
262 |
|
263 |
+
# For "Human" data, search within all "Actor_XX" subfolders
|
264 |
elif source == "Human":
|
265 |
if os.path.isdir(HUMAN_AUDIO_BASE_PATH):
|
266 |
for actor_folder in os.listdir(HUMAN_AUDIO_BASE_PATH):
|
|
|
268 |
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, actor_folder, basename)
|
269 |
if os.path.exists(expected_path):
|
270 |
return expected_path
|
271 |
+
|
272 |
+
# Try without subdirectory in case files are flat
|
273 |
+
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, basename)
|
274 |
+
if os.path.exists(expected_path):
|
275 |
+
return expected_path
|
276 |
|
277 |
# Fallback for dummy data or other cases
|
278 |
if os.path.exists(basename):
|
279 |
return basename
|
280 |
|
281 |
+
# Try in local directories (for dummy data)
|
282 |
+
if source == "Dog":
|
283 |
+
for label_dir in ["bark", "growl", "whine", "pant"]:
|
284 |
+
local_path = os.path.join(DOG_DIR, label_dir, basename)
|
285 |
+
if os.path.exists(local_path):
|
286 |
+
return local_path
|
287 |
+
elif source == "Human":
|
288 |
+
local_path = os.path.join(HUMAN_DIR, "Actor_01", basename)
|
289 |
+
if os.path.exists(local_path):
|
290 |
+
return local_path
|
291 |
+
|
292 |
+
# If all else fails, return the original basename
|
293 |
return basename
|
294 |
|
295 |
def get_cmt_data(filepath: str, lens: str):
|
|
|
620 |
)
|
621 |
|
622 |
# Primary file selection (filtered by species)
|
623 |
+
dog_files = df_combined[df_combined["source"] == "Dog"]["filepath"].astype(str).tolist()
|
624 |
+
human_files = df_combined[df_combined["source"] == "Human"]["filepath"].astype(str).tolist()
|
625 |
+
|
626 |
primary_dropdown = gr.Dropdown(
|
627 |
label="Primary Audio File",
|
628 |
+
choices=dog_files,
|
629 |
+
value=dog_files[0] if dog_files else None
|
630 |
)
|
631 |
|
632 |
# Automatically found neighbor (from opposite species)
|
633 |
neighbor_dropdown = gr.Dropdown(
|
634 |
label="Auto-Found Cross-Species Neighbor",
|
635 |
+
choices=human_files,
|
636 |
+
value=human_files[0] if human_files else None,
|
637 |
interactive=True # Allow manual override
|
638 |
)
|
639 |
|
|
|
781 |
inputs=cross_species_inputs,
|
782 |
outputs=cross_species_outputs)
|
783 |
|
784 |
+
# Initialize on load - let the pre-populated dropdowns handle the initial state
|
|
|
|
|
|
|
|
|
|
|
785 |
|
786 |
if __name__ == "__main__":
|
787 |
demo.launch(share=True, debug=True)
|