AI_DeepFake_Detection_System / audio_backend.py
bhoumik12's picture
Upload 5 files
960b635 verified
raw
history blame contribute delete
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