Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- .gitattributes +2 -0
- alert_high.mp3 +0 -0
- alert_high_soussou.m4a +3 -0
- alert_ok.mp3 +0 -0
- alert_ok_soussou.m4a +3 -0
- app.py +90 -0
- smartrack_health_alert_vet_model.pkl +3 -0
- species_encoder_vet.pkl +3 -0
- welcome.mp3 +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
alert_high_soussou.m4a filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
alert_ok_soussou.m4a filter=lfs diff=lfs merge=lfs -text
|
alert_high.mp3
ADDED
|
Binary file (51.1 kB). View file
|
|
|
alert_high_soussou.m4a
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:973d5ab7ebb81c24bc8dfb43d92740d17e77bd54ca222d2c0d1997affdab6831
|
| 3 |
+
size 163452
|
alert_ok.mp3
ADDED
|
Binary file (39.4 kB). View file
|
|
|
alert_ok_soussou.m4a
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:290d8b76ad5edbee9afe80055d33cdadf69240a5bee1bb0a4ebb49839c89fa70
|
| 3 |
+
size 157934
|
app.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# 1. Chargement des Artefacts
|
| 8 |
+
MODEL_FILE = "smartrack_health_alert_vet_model.pkl"
|
| 9 |
+
ENCODER_FILE = "species_encoder_vet.pkl"
|
| 10 |
+
|
| 11 |
+
# Assurez-vous que ces fichiers audio ont été générés en amont
|
| 12 |
+
ALERT_AUDIO = "alert_high.mp3"
|
| 13 |
+
OK_AUDIO = "alert_ok.mp3"
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
model = pickle.load(open(MODEL_FILE, "rb"))
|
| 17 |
+
encoder = pickle.load(open(ENCODER_FILE, "rb"))
|
| 18 |
+
except Exception as e:
|
| 19 |
+
# Cas d'erreur pour le déploiement
|
| 20 |
+
print(f"Erreur de chargement des artefacts : {e}")
|
| 21 |
+
model = None
|
| 22 |
+
|
| 23 |
+
classes = ['OK (Santé Normale)', 'ALERTE (Intervention Recommandée)']
|
| 24 |
+
SPECIES_LIST = list(encoder.categories_[0])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# 2. Fonction de Prédiction avec Output Audio
|
| 28 |
+
def predict_health_alert_vocal(species, hr, spo2, temp, acc_mean, gyro_mean):
|
| 29 |
+
""" Prend les données et renvoie le texte d'alerte ET le fichier audio correspondant. """
|
| 30 |
+
|
| 31 |
+
if model is None:
|
| 32 |
+
return "Erreur: Modèle non chargé.", None # Retourne le texte et l'audio (None)
|
| 33 |
+
|
| 34 |
+
input_data = pd.DataFrame({
|
| 35 |
+
'hr': [hr], 'spo2': [spo2], 'temp': [temp],
|
| 36 |
+
'acc_mean': [acc_mean], 'gyro_mean': [gyro_mean],
|
| 37 |
+
'species': [species]
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
numerical_features = input_data.drop('species', axis=1)
|
| 41 |
+
species_encoded = encoder.transform(input_data[['species']])
|
| 42 |
+
species_df = pd.DataFrame(species_encoded, columns=encoder.get_feature_names_out(['species']))
|
| 43 |
+
|
| 44 |
+
X_final = pd.concat([numerical_features, species_df], axis=1)
|
| 45 |
+
|
| 46 |
+
prediction = model.predict(X_final)[0]
|
| 47 |
+
probas = model.predict_proba(X_final)[0]
|
| 48 |
+
predicted_class = classes[prediction]
|
| 49 |
+
|
| 50 |
+
# Choix du fichier audio et du message
|
| 51 |
+
if prediction == 1:
|
| 52 |
+
audio_path = ALERT_AUDIO
|
| 53 |
+
alert_style = "🚨 **ALERTE: Problème de Santé Détecté** 🚨"
|
| 54 |
+
action_message = "Veuillez vérifier immédiatement l'animal ou consulter un vétérinaire. Écoutez l'alerte vocale ci-dessous."
|
| 55 |
+
else:
|
| 56 |
+
audio_path = OK_AUDIO
|
| 57 |
+
alert_style = "✅ **Statut de Santé: OK**"
|
| 58 |
+
action_message = "Les signes vitaux sont dans la plage normale pour l'espèce. Écoutez le message de confirmation ci-dessous."
|
| 59 |
+
|
| 60 |
+
output_text = f"## {alert_style} \n\n"
|
| 61 |
+
output_text += f"**Espèce :** {species.capitalize()}\n"
|
| 62 |
+
output_text += f"**Statut Analysé :** **{predicted_class}**\n\n"
|
| 63 |
+
output_text += f"--- \n\n"
|
| 64 |
+
output_text += f"**Action Recommandée :** {action_message}\n\n"
|
| 65 |
+
output_text += f"*(Probabilité d'Alerte : {probas[1]*100:.2f}%)*"
|
| 66 |
+
|
| 67 |
+
return output_text, audio_path # Retourne le texte ET le chemin du fichier audio
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# 3. Création de l'Interface Gradio (avec le composant Audio)
|
| 71 |
+
iface = gr.Interface(
|
| 72 |
+
fn=predict_health_alert_vocal, # Nouvelle fonction
|
| 73 |
+
inputs=[
|
| 74 |
+
gr.Dropdown(choices=SPECIES_LIST, label="1. Espèce Animale", value="boeuf"),
|
| 75 |
+
gr.Slider(minimum=30, maximum=200, value=75, label="2. Rythme Cardiaque (BPM)"),
|
| 76 |
+
gr.Slider(minimum=80, maximum=100, value=96, label="3. Saturation O₂ (SpO2 %)"),
|
| 77 |
+
gr.Slider(minimum=35.0, maximum=42.0, value=38.0, label="4. Température Corporelle (°C)"),
|
| 78 |
+
gr.Slider(minimum=0.0, maximum=5.0, value=0.5, label="5. Mouvement (Accél. Moy.)"),
|
| 79 |
+
gr.Slider(minimum=0.0, maximum=5.0, value=1.5, label="6. Mouvement (Gyro. Moy.)"),
|
| 80 |
+
],
|
| 81 |
+
outputs=[
|
| 82 |
+
gr.Markdown(label="Rapport Textuel d'Alerte"), # Premier output: Texte
|
| 83 |
+
gr.Audio(label="Alerte Vocale (Cliquez pour Écouter)"), # Deuxième output: Audio
|
| 84 |
+
],
|
| 85 |
+
title="Système d'Alerte de Santé Vétérinaire SmarTrack (Vocal)",
|
| 86 |
+
description="Le modèle prédit l'état de santé et génère une alerte vocale immédiate pour le propriétaire.",
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# if __name__ == "__main__":
|
| 90 |
+
# iface.launch()
|
smartrack_health_alert_vet_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:329d6a7e67bdcc132ce58d88b510a3a93006328470d6b71aabe8b16c23fdaec9
|
| 3 |
+
size 538942
|
species_encoder_vet.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:85758a71d689429a90099a6e24b266a78475d3d2821a54960b6248f0edb1486f
|
| 3 |
+
size 622
|
welcome.mp3
ADDED
|
Binary file (44.9 kB). View file
|
|
|