Spaces:
Sleeping
Sleeping
Delete app2.py
Browse files
app2.py
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
import tensorflow as tf
|
| 2 |
-
import joblib
|
| 3 |
-
import numpy as np
|
| 4 |
-
import gradio as gr
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
-
# Load model with correct filename
|
| 8 |
-
model = tf.keras.models.load_model("animal_sound_cnn.keras")
|
| 9 |
-
|
| 10 |
-
# Load label encoder
|
| 11 |
-
label_encoder = joblib.load("label_encoder.joblib")
|
| 12 |
-
|
| 13 |
-
def predict(audio_path):
|
| 14 |
-
try:
|
| 15 |
-
# 1. Preprocess audio (replace this with your actual preprocessing)
|
| 16 |
-
# Example placeholder - you'll need to implement your audio feature extraction
|
| 17 |
-
spectrogram = np.random.rand(1, 64, 64, 1) # Replace with real preprocessing
|
| 18 |
-
|
| 19 |
-
# 2. Predict
|
| 20 |
-
pred = model.predict(spectrogram)
|
| 21 |
-
animal = label_encoder.inverse_transform([np.argmax(pred)])[0]
|
| 22 |
-
|
| 23 |
-
return animal
|
| 24 |
-
except Exception as e:
|
| 25 |
-
return f"Error: {str(e)}"
|
| 26 |
-
|
| 27 |
-
# Gradio interface
|
| 28 |
-
gr.Interface(
|
| 29 |
-
fn=predict,
|
| 30 |
-
inputs=gr.Audio(type="filepath"),
|
| 31 |
-
outputs="label",
|
| 32 |
-
title="Animal Sound Classifier",
|
| 33 |
-
description="Upload an animal sound to identify the species"
|
| 34 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|