Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,30 @@ class DogBehaviorAnalyzer:
|
|
27 |
'high_activity': {'threshold': 0.05, 'description': 'Your dog is very energetic!'}
|
28 |
}
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# Motion detection parameters
|
31 |
self.history = []
|
32 |
self.max_history = 10
|
@@ -115,6 +139,38 @@ class DogBehaviorAnalyzer:
|
|
115 |
|
116 |
return detected_behaviors
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
def main():
|
119 |
st.title("🐕 Dog Behavior Analyzer")
|
120 |
st.write("Upload a video of your dog for behavior analysis!")
|
@@ -188,6 +244,13 @@ def main():
|
|
188 |
analysis_text += f" Count: {count} | Confidence: {avg_conf:.2f}\n"
|
189 |
analysis_text += f" {analyzer.behaviors[behavior]['description']}\n\n"
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
analysis_placeholder.text_area(
|
192 |
"Analysis Results",
|
193 |
analysis_text,
|
@@ -241,4 +304,4 @@ def main():
|
|
241 |
st.write("Upload a video to see behavior analysis!")
|
242 |
|
243 |
if __name__ == "__main__":
|
244 |
-
main()
|
|
|
27 |
'high_activity': {'threshold': 0.05, 'description': 'Your dog is very energetic!'}
|
28 |
}
|
29 |
|
30 |
+
self.suggestions = {
|
31 |
+
'tail_wagging': [
|
32 |
+
"This is a great time for positive reinforcement training!",
|
33 |
+
"Consider engaging in some fun play activities",
|
34 |
+
"Your dog is in a social mood - perfect for bonding exercises"
|
35 |
+
],
|
36 |
+
'movement': [
|
37 |
+
"A good opportunity for some basic training exercises",
|
38 |
+
"Consider introducing some puzzle toys",
|
39 |
+
"This energy level is perfect for a short training session"
|
40 |
+
],
|
41 |
+
'stationary': [
|
42 |
+
"Perfect time for gentle petting and calming interactions",
|
43 |
+
"Consider offering a chew toy for mental stimulation",
|
44 |
+
"Good moment for quiet bonding or rest"
|
45 |
+
],
|
46 |
+
'high_activity': [
|
47 |
+
"Your dog might benefit from structured exercise",
|
48 |
+
"Consider redirecting energy into agility training",
|
49 |
+
"A good play session with toys would be beneficial",
|
50 |
+
"Make sure fresh water is available"
|
51 |
+
]
|
52 |
+
}
|
53 |
+
|
54 |
# Motion detection parameters
|
55 |
self.history = []
|
56 |
self.max_history = 10
|
|
|
139 |
|
140 |
return detected_behaviors
|
141 |
|
142 |
+
def get_suggestions(self, detected_behaviors, behavior_counts):
|
143 |
+
"""Generate suggestions based on detected behaviors and their frequency"""
|
144 |
+
active_suggestions = []
|
145 |
+
|
146 |
+
# Get total frames analyzed
|
147 |
+
total_frames = sum(behavior_counts.values())
|
148 |
+
if total_frames == 0:
|
149 |
+
return []
|
150 |
+
|
151 |
+
# Calculate behavior percentages
|
152 |
+
behavior_percentages = {
|
153 |
+
behavior: count / total_frames * 100
|
154 |
+
for behavior, count in behavior_counts.items()
|
155 |
+
}
|
156 |
+
|
157 |
+
# Generate relevant suggestions based on current behaviors and their frequencies
|
158 |
+
for behavior, _ in detected_behaviors:
|
159 |
+
if behavior in self.suggestions:
|
160 |
+
# Select suggestions based on how frequently the behavior occurs
|
161 |
+
if behavior_percentages[behavior] > 30: # If behavior occurs more than 30% of the time
|
162 |
+
suggestions = self.suggestions[behavior]
|
163 |
+
active_suggestions.extend(suggestions[:2]) # Add top 2 suggestions
|
164 |
+
|
165 |
+
# Add general suggestions based on overall behavior patterns
|
166 |
+
if behavior_percentages.get('high_activity', 0) > 50:
|
167 |
+
active_suggestions.append("Consider incorporating more calming activities in your routine")
|
168 |
+
elif behavior_percentages.get('stationary', 0) > 70:
|
169 |
+
active_suggestions.append("Your dog might benefit from more physical activity")
|
170 |
+
|
171 |
+
# Remove duplicates and return
|
172 |
+
return list(set(active_suggestions))
|
173 |
+
|
174 |
def main():
|
175 |
st.title("🐕 Dog Behavior Analyzer")
|
176 |
st.write("Upload a video of your dog for behavior analysis!")
|
|
|
244 |
analysis_text += f" Count: {count} | Confidence: {avg_conf:.2f}\n"
|
245 |
analysis_text += f" {analyzer.behaviors[behavior]['description']}\n\n"
|
246 |
|
247 |
+
# Get and display suggestions
|
248 |
+
suggestions = analyzer.get_suggestions(detected_behaviors, behavior_counts)
|
249 |
+
if suggestions:
|
250 |
+
analysis_text += "\nSuggestions:\n\n"
|
251 |
+
for suggestion in suggestions:
|
252 |
+
analysis_text += f"💡 {suggestion}\n"
|
253 |
+
|
254 |
analysis_placeholder.text_area(
|
255 |
"Analysis Results",
|
256 |
analysis_text,
|
|
|
304 |
st.write("Upload a video to see behavior analysis!")
|
305 |
|
306 |
if __name__ == "__main__":
|
307 |
+
main()
|