Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -166,6 +166,17 @@ async def predict(files: List[UploadFile] = File(...)):
|
|
| 166 |
# Preprocess the audio file
|
| 167 |
waveform = preprocess_audio(temp_audio_path)
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
# Perform inference
|
| 170 |
label, confidence = infer(model_list, waveform)
|
| 171 |
|
|
@@ -181,6 +192,7 @@ async def predict(files: List[UploadFile] = File(...)):
|
|
| 181 |
"label": "Genuine" if label == 0 else "Spoof",
|
| 182 |
"confidence": confidence,
|
| 183 |
"status": "success",
|
|
|
|
| 184 |
}
|
| 185 |
responses.append(response)
|
| 186 |
|
|
|
|
| 166 |
# Preprocess the audio file
|
| 167 |
waveform = preprocess_audio(temp_audio_path)
|
| 168 |
|
| 169 |
+
rms = torch.sqrt(torch.mean(waveform**2)).item()
|
| 170 |
+
volume = "normal"
|
| 171 |
+
|
| 172 |
+
if rms < 0.0005:
|
| 173 |
+
volume = "silent"
|
| 174 |
+
elif rms < 0.01:
|
| 175 |
+
volume = "augmented"
|
| 176 |
+
waveform = waveform * 10 # Apply gain boost
|
| 177 |
+
|
| 178 |
+
logger.info(f"Volume state for {file.filename}: {volume}")
|
| 179 |
+
|
| 180 |
# Perform inference
|
| 181 |
label, confidence = infer(model_list, waveform)
|
| 182 |
|
|
|
|
| 192 |
"label": "Genuine" if label == 0 else "Spoof",
|
| 193 |
"confidence": confidence,
|
| 194 |
"status": "success",
|
| 195 |
+
"volume":volume
|
| 196 |
}
|
| 197 |
responses.append(response)
|
| 198 |
|