Spaces:
Running
Running
Updated analyze function
Browse filesIf the transcript is provided, Whisper ASR is not triggered anymore.
main.py
CHANGED
|
@@ -195,7 +195,16 @@ async def analyze(audio: UploadFile = File(...), video: UploadFile = File(None),
|
|
| 195 |
try:
|
| 196 |
with open(raw_audio, "wb") as f: shutil.copyfileobj(audio.file, f)
|
| 197 |
await asyncio.to_thread(to_wav, raw_audio, wav_path)
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# 1. Feature Extraction Pipeline
|
| 201 |
text_feat, wavlm_feat = await asyncio.gather(
|
|
@@ -213,7 +222,6 @@ async def analyze(audio: UploadFile = File(...), video: UploadFile = File(None),
|
|
| 213 |
clinical_threshold = 0.45
|
| 214 |
prediction = 1 if prob >= clinical_threshold else 0
|
| 215 |
|
| 216 |
-
# Returning logits as 'confidence' perfectly syncs with your React App's sigmoid gauge
|
| 217 |
return {
|
| 218 |
"prediction": prediction,
|
| 219 |
"label": "High Likelihood" if prediction == 1 else "Low Likelihood",
|
|
|
|
| 195 |
try:
|
| 196 |
with open(raw_audio, "wb") as f: shutil.copyfileobj(audio.file, f)
|
| 197 |
await asyncio.to_thread(to_wav, raw_audio, wav_path)
|
| 198 |
+
|
| 199 |
+
# --- THE FIX: Skip Whisper if a transcript is uploaded ---
|
| 200 |
+
if transcript is not None:
|
| 201 |
+
log.info(" [Transcript] File provided! Skipping Whisper...")
|
| 202 |
+
tsv_bytes = await transcript.read()
|
| 203 |
+
transcribed_text = tsv_bytes.decode("utf-8")
|
| 204 |
+
else:
|
| 205 |
+
log.info(" [Whisper] No transcript provided. Running Whisper...")
|
| 206 |
+
transcribed_text = await asyncio.to_thread(_transcribe_wav, wav_path)
|
| 207 |
+
# ---------------------------------------------------------
|
| 208 |
|
| 209 |
# 1. Feature Extraction Pipeline
|
| 210 |
text_feat, wavlm_feat = await asyncio.gather(
|
|
|
|
| 222 |
clinical_threshold = 0.45
|
| 223 |
prediction = 1 if prob >= clinical_threshold else 0
|
| 224 |
|
|
|
|
| 225 |
return {
|
| 226 |
"prediction": prediction,
|
| 227 |
"label": "High Likelihood" if prediction == 1 else "Low Likelihood",
|