Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,24 @@
|
|
| 1 |
-
import
|
| 2 |
import librosa
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
model = joblib.load(MODEL_PATH)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
def extract_mfcc(file_path):
|
| 12 |
y, sr = librosa.load(file_path, sr=None)
|
| 13 |
mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
|
| 14 |
return np.mean(mfcc, axis=1)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
def predict_audio(audio_file):
|
| 18 |
try:
|
| 19 |
features = extract_mfcc(audio_file).reshape(1, -1)
|
|
@@ -22,14 +27,20 @@ def predict_audio(audio_file):
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"Error: {e}"
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
import librosa
|
| 3 |
import numpy as np
|
| 4 |
+
import joblib
|
| 5 |
import gradio as gr
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
|
| 8 |
+
# Download the model from Hugging Face Hub
|
| 9 |
+
MODEL_REPO = "sangambhamare/TruthDetection"
|
| 10 |
+
MODEL_FILENAME = "model.joblib"
|
| 11 |
|
| 12 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILENAME)
|
| 13 |
+
model = joblib.load(model_path)
|
|
|
|
| 14 |
|
| 15 |
+
# MFCC extraction
|
| 16 |
def extract_mfcc(file_path):
|
| 17 |
y, sr = librosa.load(file_path, sr=None)
|
| 18 |
mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
|
| 19 |
return np.mean(mfcc, axis=1)
|
| 20 |
|
| 21 |
+
# Prediction
|
| 22 |
def predict_audio(audio_file):
|
| 23 |
try:
|
| 24 |
features = extract_mfcc(audio_file).reshape(1, -1)
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return f"Error: {e}"
|
| 29 |
|
| 30 |
+
# Gradio UI
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("<h1 style='text-align: center;'>Truth Detection from Audio Stories</h1>")
|
| 33 |
+
gr.Markdown(
|
| 34 |
+
"<p style='text-align: center;'>"
|
| 35 |
+
"This tool analyzes a 30-second audio story and predicts whether it is true or deceptive "
|
| 36 |
+
"based on MFCC features and a trained Random Forest classifier."
|
| 37 |
+
"</p>"
|
| 38 |
+
)
|
| 39 |
+
audio_input = gr.Audio(type="filepath", label="Upload WAV Audio File (30 seconds)")
|
| 40 |
+
output = gr.Textbox(label="Prediction")
|
| 41 |
+
submit_btn = gr.Button("Predict")
|
| 42 |
+
submit_btn.click(fn=predict_audio, inputs=audio_input, outputs=output)
|
| 43 |
+
gr.Markdown("<p style='text-align: center; font-size: 12px; color: gray;'>Developed by Sangam Sanjay Bhamare, 2025.</p>")
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|