Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,17 +77,26 @@ if os.path.exists("/content/drive/MyDrive/combined"):
|
|
| 77 |
DOG_AUDIO_BASE_PATH = '/content/drive/MyDrive/combined'
|
| 78 |
HUMAN_AUDIO_BASE_PATH = '/content/drive/MyDrive/human'
|
| 79 |
print("Using Google Drive audio paths")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
elif os.path.exists("audio/combined"):
|
| 81 |
-
# Hugging Face Spaces
|
| 82 |
DOG_AUDIO_BASE_PATH = 'audio/combined'
|
| 83 |
HUMAN_AUDIO_BASE_PATH = 'audio/human'
|
| 84 |
-
print("Using Hugging Face Spaces audio paths")
|
| 85 |
else:
|
| 86 |
# Fallback to local dummy paths
|
| 87 |
DOG_AUDIO_BASE_PATH = DOG_DIR
|
| 88 |
HUMAN_AUDIO_BASE_PATH = HUMAN_DIR
|
| 89 |
print("Using local dummy audio paths")
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# ---------------------------------------------------------------
|
| 93 |
# Cross-Species Analysis Functions
|
|
@@ -291,32 +300,42 @@ def resolve_audio_path(row: pd.Series) -> str:
|
|
| 291 |
source = row.get("source", "")
|
| 292 |
label = row.get("label", "")
|
| 293 |
|
|
|
|
|
|
|
|
|
|
| 294 |
# For "Dog" data, the structure is: combined/{label}/{filename}
|
| 295 |
if source == "Dog":
|
|
|
|
| 296 |
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, label, basename)
|
|
|
|
| 297 |
if os.path.exists(expected_path):
|
| 298 |
return expected_path
|
| 299 |
|
| 300 |
# Try without subdirectory in case files are flat
|
| 301 |
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, basename)
|
|
|
|
| 302 |
if os.path.exists(expected_path):
|
| 303 |
return expected_path
|
| 304 |
|
| 305 |
# For "Human" data, search within all "Actor_XX" subfolders
|
| 306 |
elif source == "Human":
|
| 307 |
if os.path.isdir(HUMAN_AUDIO_BASE_PATH):
|
|
|
|
| 308 |
for actor_folder in os.listdir(HUMAN_AUDIO_BASE_PATH):
|
| 309 |
if actor_folder.startswith("Actor_"):
|
| 310 |
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, actor_folder, basename)
|
|
|
|
| 311 |
if os.path.exists(expected_path):
|
| 312 |
return expected_path
|
| 313 |
|
| 314 |
# Try without subdirectory in case files are flat
|
| 315 |
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, basename)
|
|
|
|
| 316 |
if os.path.exists(expected_path):
|
| 317 |
return expected_path
|
| 318 |
|
| 319 |
# Fallback for dummy data or other cases
|
|
|
|
| 320 |
if os.path.exists(basename):
|
| 321 |
return basename
|
| 322 |
|
|
@@ -324,14 +343,17 @@ def resolve_audio_path(row: pd.Series) -> str:
|
|
| 324 |
if source == "Dog":
|
| 325 |
for label_dir in ["bark", "growl", "whine", "pant"]:
|
| 326 |
local_path = os.path.join(DOG_DIR, label_dir, basename)
|
|
|
|
| 327 |
if os.path.exists(local_path):
|
| 328 |
return local_path
|
| 329 |
elif source == "Human":
|
| 330 |
local_path = os.path.join(HUMAN_DIR, "Actor_01", basename)
|
|
|
|
| 331 |
if os.path.exists(local_path):
|
| 332 |
return local_path
|
| 333 |
|
| 334 |
# If all else fails, return the original basename
|
|
|
|
| 335 |
return basename
|
| 336 |
|
| 337 |
def get_cmt_data(filepath: str, lens: str):
|
|
@@ -786,7 +808,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal", secondary_hue="cyan")) a
|
|
| 786 |
|
| 787 |
# Audio files
|
| 788 |
primary_audio = primary_fp if primary_fp and os.path.exists(primary_fp) else None
|
| 789 |
-
neighbor_audio = neighbor_fp if neighbor_row and neighbor_fp and os.path.exists(neighbor_fp) else None
|
| 790 |
|
| 791 |
return (dual_holo_fig, dual_diag_fig, primary_info, neighbor_info,
|
| 792 |
primary_audio, neighbor_audio)
|
|
|
|
| 77 |
DOG_AUDIO_BASE_PATH = '/content/drive/MyDrive/combined'
|
| 78 |
HUMAN_AUDIO_BASE_PATH = '/content/drive/MyDrive/human'
|
| 79 |
print("Using Google Drive audio paths")
|
| 80 |
+
elif os.path.exists("combined") and os.path.exists("human"):
|
| 81 |
+
# Hugging Face Spaces with audio in repo root
|
| 82 |
+
DOG_AUDIO_BASE_PATH = 'combined'
|
| 83 |
+
HUMAN_AUDIO_BASE_PATH = 'human'
|
| 84 |
+
print("Using Hugging Face Spaces audio paths (repo root)")
|
| 85 |
elif os.path.exists("audio/combined"):
|
| 86 |
+
# Alternative Hugging Face Spaces location
|
| 87 |
DOG_AUDIO_BASE_PATH = 'audio/combined'
|
| 88 |
HUMAN_AUDIO_BASE_PATH = 'audio/human'
|
| 89 |
+
print("Using Hugging Face Spaces audio paths (audio subdir)")
|
| 90 |
else:
|
| 91 |
# Fallback to local dummy paths
|
| 92 |
DOG_AUDIO_BASE_PATH = DOG_DIR
|
| 93 |
HUMAN_AUDIO_BASE_PATH = HUMAN_DIR
|
| 94 |
print("Using local dummy audio paths")
|
| 95 |
|
| 96 |
+
print(f"Audio base paths configured:")
|
| 97 |
+
print(f"- Dog audio base: {DOG_AUDIO_BASE_PATH}")
|
| 98 |
+
print(f"- Human audio base: {HUMAN_AUDIO_BASE_PATH}")
|
| 99 |
+
|
| 100 |
|
| 101 |
# ---------------------------------------------------------------
|
| 102 |
# Cross-Species Analysis Functions
|
|
|
|
| 300 |
source = row.get("source", "")
|
| 301 |
label = row.get("label", "")
|
| 302 |
|
| 303 |
+
# Debug information
|
| 304 |
+
print(f"🔍 Resolving audio path for: {basename} ({source}, {label})")
|
| 305 |
+
|
| 306 |
# For "Dog" data, the structure is: combined/{label}/{filename}
|
| 307 |
if source == "Dog":
|
| 308 |
+
# Try with label subdirectory first
|
| 309 |
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, label, basename)
|
| 310 |
+
print(f" Trying dog path: {expected_path} (exists: {os.path.exists(expected_path)})")
|
| 311 |
if os.path.exists(expected_path):
|
| 312 |
return expected_path
|
| 313 |
|
| 314 |
# Try without subdirectory in case files are flat
|
| 315 |
expected_path = os.path.join(DOG_AUDIO_BASE_PATH, basename)
|
| 316 |
+
print(f" Trying flat dog path: {expected_path} (exists: {os.path.exists(expected_path)})")
|
| 317 |
if os.path.exists(expected_path):
|
| 318 |
return expected_path
|
| 319 |
|
| 320 |
# For "Human" data, search within all "Actor_XX" subfolders
|
| 321 |
elif source == "Human":
|
| 322 |
if os.path.isdir(HUMAN_AUDIO_BASE_PATH):
|
| 323 |
+
print(f" Searching in human base: {HUMAN_AUDIO_BASE_PATH}")
|
| 324 |
for actor_folder in os.listdir(HUMAN_AUDIO_BASE_PATH):
|
| 325 |
if actor_folder.startswith("Actor_"):
|
| 326 |
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, actor_folder, basename)
|
| 327 |
+
print(f" Trying: {expected_path} (exists: {os.path.exists(expected_path)})")
|
| 328 |
if os.path.exists(expected_path):
|
| 329 |
return expected_path
|
| 330 |
|
| 331 |
# Try without subdirectory in case files are flat
|
| 332 |
expected_path = os.path.join(HUMAN_AUDIO_BASE_PATH, basename)
|
| 333 |
+
print(f" Trying flat human path: {expected_path} (exists: {os.path.exists(expected_path)})")
|
| 334 |
if os.path.exists(expected_path):
|
| 335 |
return expected_path
|
| 336 |
|
| 337 |
# Fallback for dummy data or other cases
|
| 338 |
+
print(f" Trying basename directly: {basename} (exists: {os.path.exists(basename)})")
|
| 339 |
if os.path.exists(basename):
|
| 340 |
return basename
|
| 341 |
|
|
|
|
| 343 |
if source == "Dog":
|
| 344 |
for label_dir in ["bark", "growl", "whine", "pant"]:
|
| 345 |
local_path = os.path.join(DOG_DIR, label_dir, basename)
|
| 346 |
+
print(f" Trying local dog path: {local_path} (exists: {os.path.exists(local_path)})")
|
| 347 |
if os.path.exists(local_path):
|
| 348 |
return local_path
|
| 349 |
elif source == "Human":
|
| 350 |
local_path = os.path.join(HUMAN_DIR, "Actor_01", basename)
|
| 351 |
+
print(f" Trying local human path: {local_path} (exists: {os.path.exists(local_path)})")
|
| 352 |
if os.path.exists(local_path):
|
| 353 |
return local_path
|
| 354 |
|
| 355 |
# If all else fails, return the original basename
|
| 356 |
+
print(f" ❌ No valid path found, returning basename: {basename}")
|
| 357 |
return basename
|
| 358 |
|
| 359 |
def get_cmt_data(filepath: str, lens: str):
|
|
|
|
| 808 |
|
| 809 |
# Audio files
|
| 810 |
primary_audio = primary_fp if primary_fp and os.path.exists(primary_fp) else None
|
| 811 |
+
neighbor_audio = neighbor_fp if neighbor_row is not None and neighbor_fp and os.path.exists(neighbor_fp) else None
|
| 812 |
|
| 813 |
return (dual_holo_fig, dual_diag_fig, primary_info, neighbor_info,
|
| 814 |
primary_audio, neighbor_audio)
|