Download app.py from Prabin1/Audio_Deepfake_Detection_Model: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/Prabin1/Audio_Deepfake_Detection_Model/resolve/main/app.py
- Command line
-
hf download hf://spaces/Prabin1/Audio_Deepfake_Detection_Model/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Prabin1/Audio_Deepfake_Detection_Model/resolve/main/app.py
1.14 kB
| 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) | |