File size: 951 Bytes
452d5c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import librosa
import numpy as np
from tensorflow.keras.models import load_model

# Load Keras model
model = load_model("CNN_dataaug_with_2freqtimelrand_masking_situation.keras")

# Example labels (edit these based on training labels if needed)
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()