File size: 1,136 Bytes
70426d0 38f41fa 70426d0 38f41fa 6e32606 70426d0 38f41fa 5448ba6 6e32606 70426d0 5448ba6 70426d0 5448ba6 6e32606 70426d0 5448ba6 6e32606 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import gradio as gr
import numpy as np
from audio_features import extract_features_with_time_series
from model_utils import load_model, prepare_input_for_model, interpret_prediction
MODEL_PATH = "best_audio_model.keras"
# Load the model once
model = load_model(MODEL_PATH)
def predict_audio(file_path):
try:
features = extract_features_with_time_series(file_path)
if features is None:
return {"Error": "Feature extraction failed. Please check the audio file."}
input_data = prepare_input_for_model(features, model)
raw_pred = model.predict(input_data)
result = interpret_prediction(raw_pred)
return result
except Exception as e:
return {"Error": str(e)}
iface = gr.Interface(
fn=predict_audio,
inputs=gr.Audio(type="filepath", label="Upload an audio file"),
outputs=gr.Label(num_top_classes=2, label="Prediction"),
title="Audio Deepfake Detection",
description="Upload an audio clip to check if it's Real or Fake using your trained .keras model."
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)
|