Spaces:
Runtime error
Runtime error
fixed gender parsing for int/string in firebase
Browse files- crew.py +1 -3
- dataloaderImp.py +18 -5
crew.py
CHANGED
|
@@ -72,9 +72,7 @@ def calculate_dementia_risk_audio(docID: str, return_json: bool = False) -> Unio
|
|
| 72 |
except json.JSONDecodeError:
|
| 73 |
pass
|
| 74 |
|
| 75 |
-
|
| 76 |
-
from dataloaderImp import pull_audio_features_from_firebase
|
| 77 |
-
audio_data = pull_audio_features_from_firebase(docID)
|
| 78 |
|
| 79 |
if audio_data is None:
|
| 80 |
error_msg = f"Error: Could not retrieve or process audio data for patient '{docID}'"
|
|
|
|
| 72 |
except json.JSONDecodeError:
|
| 73 |
pass
|
| 74 |
|
| 75 |
+
audio_data = pull_audio(docID)
|
|
|
|
|
|
|
| 76 |
|
| 77 |
if audio_data is None:
|
| 78 |
error_msg = f"Error: Could not retrieve or process audio data for patient '{docID}'"
|
dataloaderImp.py
CHANGED
|
@@ -55,7 +55,7 @@ def extract_text_features(cha_path):
|
|
| 55 |
print(f"Text extraction failed for {cha_path}: {e}")
|
| 56 |
return None
|
| 57 |
|
| 58 |
-
def
|
| 59 |
"""
|
| 60 |
Downloads .wav from Firebase Storage, fetches age/gender from Firestore,
|
| 61 |
checks for existing .cha and .txt in Firebase Storage.
|
|
@@ -71,11 +71,24 @@ def pull_audio_features_from_firebase(docID: str):
|
|
| 71 |
return None
|
| 72 |
data = doc.to_dict()
|
| 73 |
age = data.get("age")
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return None
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
# 2. Ensure .wav exists
|
| 81 |
wav_blob = bucket.blob(f"audiostuff/wav/{docID}.wav")
|
|
|
|
| 55 |
print(f"Text extraction failed for {cha_path}: {e}")
|
| 56 |
return None
|
| 57 |
|
| 58 |
+
def pull_audio(docID: str):
|
| 59 |
"""
|
| 60 |
Downloads .wav from Firebase Storage, fetches age/gender from Firestore,
|
| 61 |
checks for existing .cha and .txt in Firebase Storage.
|
|
|
|
| 71 |
return None
|
| 72 |
data = doc.to_dict()
|
| 73 |
age = data.get("age")
|
| 74 |
+
gender_val = data.get("gender")
|
| 75 |
+
|
| 76 |
+
if age is None or gender_val is None:
|
| 77 |
+
print(f"Missing age or gender for {docID}")
|
| 78 |
+
return None
|
| 79 |
+
|
| 80 |
+
# Ensure gender is integer
|
| 81 |
+
try:
|
| 82 |
+
gender = int(gender_val)
|
| 83 |
+
except (ValueError, TypeError):
|
| 84 |
+
print(f"Invalid gender value '{gender_val}' for {docID} (expected 0 or 1)")
|
| 85 |
return None
|
| 86 |
+
|
| 87 |
+
if gender not in (0, 1):
|
| 88 |
+
print(f"Gender must be 0 or 1, got {gender} for {docID}")
|
| 89 |
+
return None
|
| 90 |
+
|
| 91 |
+
gender_str = "male" if gender == 1 else "female"
|
| 92 |
|
| 93 |
# 2. Ensure .wav exists
|
| 94 |
wav_blob = bucket.blob(f"audiostuff/wav/{docID}.wav")
|