Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -41,17 +41,52 @@ DATA_DIR = os.path.join(BASE_DIR, "data")
|
|
41 |
DOG_DIR = os.path.join(DATA_DIR, "dog")
|
42 |
HUMAN_DIR = os.path.join(DATA_DIR, "human")
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# These are for creating dummy audio files if needed
|
49 |
os.makedirs(DOG_DIR, exist_ok=True)
|
50 |
os.makedirs(os.path.join(HUMAN_DIR, "Actor_01"), exist_ok=True)
|
51 |
|
52 |
-
# --- Audio Data Configuration (
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
# ---------------------------------------------------------------
|
@@ -105,13 +140,20 @@ def find_nearest_cross_species_neighbor(selected_row, df_combined, n_neighbors=5
|
|
105 |
# ---------------------------------------------------------------
|
106 |
# Load datasets (Colab-first paths)
|
107 |
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
if os.path.exists(CSV_DOG) and os.path.exists(CSV_HUMAN):
|
109 |
-
print(f"Found existing data files. Loading from:\n- {CSV_DOG}\n- {CSV_HUMAN}")
|
110 |
df_dog = pd.read_csv(CSV_DOG)
|
111 |
df_human = pd.read_csv(CSV_HUMAN)
|
112 |
-
print("Successfully loaded data
|
113 |
else:
|
114 |
-
print("Could not find one or both CSV files. Generating and using in-memory dummy data.")
|
115 |
|
116 |
# This section is for DUMMY DATA GENERATION ONLY.
|
117 |
# It runs if the primary CSVs are not found and does NOT write files.
|
|
|
41 |
DOG_DIR = os.path.join(DATA_DIR, "dog")
|
42 |
HUMAN_DIR = os.path.join(DATA_DIR, "human")
|
43 |
|
44 |
+
# Paths for different deployment environments
|
45 |
+
# Priority order: 1) Hugging Face Spaces (repo root), 2) Colab, 3) Local
|
46 |
+
HF_CSV_DOG = "cmt_dog_sound_analysis.csv"
|
47 |
+
HF_CSV_HUMAN = "cmt_human_speech_analysis.csv"
|
48 |
+
COLAB_CSV_DOG = "/content/cmt_dog_sound_analysis.csv"
|
49 |
+
COLAB_CSV_HUMAN = "/content/cmt_human_speech_analysis.csv"
|
50 |
+
|
51 |
+
# Determine which environment we're in and set paths accordingly
|
52 |
+
if os.path.exists(HF_CSV_DOG) and os.path.exists(HF_CSV_HUMAN):
|
53 |
+
# Hugging Face Spaces - files in repo root
|
54 |
+
CSV_DOG = HF_CSV_DOG
|
55 |
+
CSV_HUMAN = HF_CSV_HUMAN
|
56 |
+
print("Using Hugging Face Spaces paths")
|
57 |
+
elif os.path.exists(COLAB_CSV_DOG) and os.path.exists(COLAB_CSV_HUMAN):
|
58 |
+
# Google Colab environment
|
59 |
+
CSV_DOG = COLAB_CSV_DOG
|
60 |
+
CSV_HUMAN = COLAB_CSV_HUMAN
|
61 |
+
print("Using Google Colab paths")
|
62 |
+
else:
|
63 |
+
# Fallback to local or will trigger dummy data
|
64 |
+
CSV_DOG = HF_CSV_DOG # Try repo root first
|
65 |
+
CSV_HUMAN = HF_CSV_HUMAN
|
66 |
+
print("Falling back to local/dummy data paths")
|
67 |
|
68 |
# These are for creating dummy audio files if needed
|
69 |
os.makedirs(DOG_DIR, exist_ok=True)
|
70 |
os.makedirs(os.path.join(HUMAN_DIR, "Actor_01"), exist_ok=True)
|
71 |
|
72 |
+
# --- Audio Data Configuration (Platform-aware paths) ---
|
73 |
+
# For Hugging Face Spaces, audio files might be in the repo or need different handling
|
74 |
+
# For Colab, they're in Google Drive
|
75 |
+
if os.path.exists("/content/drive/MyDrive/combined"):
|
76 |
+
# Google Colab with mounted Drive
|
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 with audio in repo
|
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 |
# ---------------------------------------------------------------
|
|
|
140 |
# ---------------------------------------------------------------
|
141 |
# Load datasets (Colab-first paths)
|
142 |
# ---------------------------------------------------------------
|
143 |
+
# Debug: Show what files we're looking for and what exists
|
144 |
+
print(f"Looking for CSV files:")
|
145 |
+
print(f"- Dog CSV: {CSV_DOG} (exists: {os.path.exists(CSV_DOG)})")
|
146 |
+
print(f"- Human CSV: {CSV_HUMAN} (exists: {os.path.exists(CSV_HUMAN)})")
|
147 |
+
print(f"Current working directory: {os.getcwd()}")
|
148 |
+
print(f"Files in current directory: {os.listdir('.')}")
|
149 |
+
|
150 |
if os.path.exists(CSV_DOG) and os.path.exists(CSV_HUMAN):
|
151 |
+
print(f"✅ Found existing data files. Loading from:\n- {CSV_DOG}\n- {CSV_HUMAN}")
|
152 |
df_dog = pd.read_csv(CSV_DOG)
|
153 |
df_human = pd.read_csv(CSV_HUMAN)
|
154 |
+
print(f"Successfully loaded data: {len(df_dog)} dog rows, {len(df_human)} human rows")
|
155 |
else:
|
156 |
+
print("❌ Could not find one or both CSV files. Generating and using in-memory dummy data.")
|
157 |
|
158 |
# This section is for DUMMY DATA GENERATION ONLY.
|
159 |
# It runs if the primary CSVs are not found and does NOT write files.
|