|
|
import gradio as gr |
|
|
import librosa |
|
|
import numpy as np |
|
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
|
|
|
model = load_model("CNN_dataaug_with_2freqtimelrand_masking_situation.keras") |
|
|
|
|
|
|
|
|
labels = ['attention', 'annoyed', 'food', 'happy', 'pain', 'mating'] |
|
|
|
|
|
def predict_meow(audio_file): |
|
|
if audio_file is None: |
|
|
return "Upload a valid meow audio" |
|
|
|
|
|
y, sr = librosa.load(audio_file, sr=16000) |
|
|
mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13) |
|
|
mfcc = np.mean(mfcc.T, axis=0).reshape(1, -1) |
|
|
|
|
|
pred = model.predict(mfcc)[0] |
|
|
label = labels[np.argmax(pred)] |
|
|
return f"Predicted Cat Mood: {label}" |
|
|
|
|
|
gr.Interface( |
|
|
fn=predict_meow, |
|
|
inputs=gr.Audio(type="filepath", label="Upload Cat Meow"), |
|
|
outputs="text", |
|
|
title="Cat Mood Detector 🐱", |
|
|
description="Upload a cat meow to detect the mood: hungry, happy, annoyed, etc." |
|
|
).launch() |