Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from audio_features import extract_features_with_time_series
|
| 3 |
+
from model_utils import load_model, prepare_input_for_model, interpret_prediction
|
| 4 |
+
|
| 5 |
+
MODEL_PATH = "your_model.keras"
|
| 6 |
+
model = load_model(MODEL_PATH)
|
| 7 |
+
|
| 8 |
+
def predict(audio_filepath):
|
| 9 |
+
try:
|
| 10 |
+
if audio_filepath is None:
|
| 11 |
+
return {"error": "No audio file provided."}
|
| 12 |
+
|
| 13 |
+
```
|
| 14 |
+
feats = extract_features_with_time_series(audio_filepath)
|
| 15 |
+
if feats is None:
|
| 16 |
+
return {"error": "Feature extraction failed."}
|
| 17 |
+
|
| 18 |
+
X = prepare_input_for_model(feats, model)
|
| 19 |
+
raw_pred = model.predict(X)
|
| 20 |
+
return interpret_prediction(raw_pred)
|
| 21 |
+
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return {"error": f"Prediction error: {e}"}
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=predict,
|
| 28 |
+
inputs=gr.Audio(source="upload", type="filepath", label="Upload audio file"),
|
| 29 |
+
outputs=gr.Label(num_top_classes=2, label="Prediction (probabilities)"),
|
| 30 |
+
title="Deepfake Audio Detector",
|
| 31 |
+
description="Upload an audio file (wav/mp3). The app extracts MFCC/LFCC/etc. features, then runs your .keras model."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if **name** == "**main**":
|
| 35 |
+
iface.launch()
|