Download audio_backend.py from bhoumik12/AI_DeepFake_Detection_System: direct link, hf CLI and curl.
- Browser
- Download file 604 Bytes
-
https://huggingface.co/spaces/bhoumik12/AI_DeepFake_Detection_System/resolve/main/audio_backend.py
- Command line
-
hf download hf://spaces/bhoumik12/AI_DeepFake_Detection_System/audio_backend.py
-
curl -L -o audio_backend.py https://huggingface.co/spaces/bhoumik12/AI_DeepFake_Detection_System/resolve/main/audio_backend.py
604 Bytes
| import tensorflow as tf | |
| import numpy as np | |
| from audio_utils import audio_to_spectrogram | |
| MODEL_PATH = "models/audio_vit_savedmodel" | |
| model = tf.saved_model.load(MODEL_PATH) | |
| infer = model.signatures["serving_default"] | |
| def predict_audio(wav_file): | |
| spec_img = audio_to_spectrogram(wav_file) | |
| x = spec_img.astype("float32") / 255.0 | |
| x = np.expand_dims(x, axis=0) | |
| preds = infer(tf.constant(x)) | |
| prob = list(preds.values())[0].numpy()[0][0] | |
| label = "Fake" if prob >= 0.5 else "Real" | |
| confidence = prob * 100 | |
| return label, round(confidence, 2), spec_img | |