Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,36 @@
|
|
| 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 = "
|
|
|
|
|
|
|
|
|
|
| 6 |
model = load_model(MODEL_PATH)
|
| 7 |
|
| 8 |
-
def
|
| 9 |
try:
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
```
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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 {"
|
| 24 |
```
|
| 25 |
|
| 26 |
iface = gr.Interface(
|
| 27 |
-
fn=
|
| 28 |
-
inputs=gr.Audio(
|
| 29 |
-
outputs=gr.Label(num_top_classes=2, label="Prediction
|
| 30 |
-
title="
|
| 31 |
-
description="Upload an audio
|
| 32 |
)
|
| 33 |
|
| 34 |
if **name** == "**main**":
|
| 35 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
from audio_features import extract_features_with_time_series
|
| 4 |
from model_utils import load_model, prepare_input_for_model, interpret_prediction
|
| 5 |
|
| 6 |
+
MODEL_PATH = "best_audio_model.keras"
|
| 7 |
+
|
| 8 |
+
# Load model once when the app starts
|
| 9 |
+
|
| 10 |
model = load_model(MODEL_PATH)
|
| 11 |
|
| 12 |
+
def predict_audio(file_path):
|
| 13 |
try:
|
| 14 |
+
features = extract_features_with_time_series(file_path)
|
| 15 |
+
if features is None:
|
| 16 |
+
return {"Error": "Feature extraction failed. Please check the audio."}
|
| 17 |
|
| 18 |
```
|
| 19 |
+
input_data = prepare_input_for_model(features, model)
|
| 20 |
+
raw_pred = model.predict(input_data)
|
| 21 |
+
result = interpret_prediction(raw_pred)
|
| 22 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
except Exception as e:
|
| 24 |
+
return {"Error": str(e)}
|
| 25 |
```
|
| 26 |
|
| 27 |
iface = gr.Interface(
|
| 28 |
+
fn=predict_audio,
|
| 29 |
+
inputs=gr.Audio(type="filepath", label="Upload an audio file"),
|
| 30 |
+
outputs=gr.Label(num_top_classes=2, label="Prediction"),
|
| 31 |
+
title="Audio Deepfake Detection",
|
| 32 |
+
description="Upload an audio clip to detect whether it is Real or Fake using a Keras model."
|
| 33 |
)
|
| 34 |
|
| 35 |
if **name** == "**main**":
|
| 36 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|