Spaces:
Sleeping
Sleeping
import gradio as gr | |
import librosa | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow import keras | |
# Load trained model | |
model = keras.models.load_model("engine_sound_model.h5") | |
# Class labels | |
labels = ["normal", "faulty", "background_noise", "unknown"] | |
def predict_engine_sound(audio_file): | |
y, sr = librosa.load(audio_file, sr=22050) | |
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13) | |
features = np.mean(mfccs.T, axis=0) | |
features = np.expand_dims(features, axis=0) | |
prediction = model.predict(features) | |
return labels[np.argmax(prediction)] | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=predict_engine_sound, | |
inputs=gr.Audio(type="filepath"), | |
outputs="text", | |
title="Engine Sound Fault Detector", | |
description="Upload an engine sound and the model will classify it as normal, faulty, or background noise." | |
) | |
# Launch the Gradio app | |
iface.launch() | |