File size: 1,465 Bytes
768c4a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
import joblib
import librosa
import numpy as np
import gradio as gr

# Load the trained Random Forest model
MODEL_PATH = "model.joblib"
model = joblib.load(MODEL_PATH)

# Function to extract MFCC features
def extract_mfcc(file_path):
    y, sr = librosa.load(file_path, sr=None)
    mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
    return np.mean(mfcc, axis=1)

# Prediction function
def predict_audio(audio_file):
    try:
        features = extract_mfcc(audio_file).reshape(1, -1)
        prediction = model.predict(features)[0]
        return "True Story" if prediction == 1 else "Deceptive Story"
    except Exception as e:
        return f"Error during prediction: {e}"

# Gradio Blocks layout
with gr.Blocks() as demo:
    gr.Markdown("<h1 style='text-align: center;'>Truth Detection from Audio Stories</h1>")
    gr.Markdown(
        "<p style='text-align: center;'>"
        "This tool analyzes an audio story and predicts whether it is true or deceptive "
        "based on MFCC features and a trained Random Forest classifier."
        "</p>"
    )
    audio_input = gr.Audio(type="filepath", label="Upload Audio File")
    output = gr.Textbox(label="Prediction")
    submit_btn = gr.Button("Predict")
    submit_btn.click(fn=predict_audio, inputs=audio_input, outputs=output)
    gr.Markdown("<p style='text-align: center; font-size: 12px; color: gray;'>Developed by Sangam Sanjay Bhamare, 2025.</p>")

if __name__ == "__main__":
    demo.launch()