|
import streamlit as st |
|
import cv2 |
|
import numpy as np |
|
from PIL import Image |
|
import tempfile |
|
import time |
|
|
|
class DogLanguageInterpreter: |
|
def __init__(self): |
|
|
|
self.emotions = { |
|
'tail_wagging': 'Happy and excited', |
|
'ears_perked': 'Alert and interested', |
|
'lying_down': 'Relaxed or tired', |
|
'barking': 'Trying to communicate', |
|
'jumping': 'Enthusiastic and playful' |
|
} |
|
|
|
def analyze_video(self, video_file): |
|
|
|
|
|
return { |
|
'primary_emotion': 'Happy and excited', |
|
'confidence': 0.85, |
|
'actions_detected': ['tail_wagging', 'jumping'], |
|
'recommendations': [ |
|
'Your dog seems very playful!', |
|
'Consider engaging in some active play', |
|
'Reward this positive energy with treats' |
|
] |
|
} |
|
|
|
def main(): |
|
st.set_page_config( |
|
page_title="Dog Language Interpreter", |
|
page_icon="π", |
|
layout="wide" |
|
) |
|
|
|
|
|
st.title("π Pet Dog Language Understanding") |
|
st.markdown(""" |
|
Upload a video of your dog, and our AI will help interpret their behavior and emotions! |
|
""") |
|
|
|
|
|
interpreter = DogLanguageInterpreter() |
|
|
|
|
|
video_file = st.file_uploader("Upload a video of your dog", type=['mp4', 'mov', 'avi']) |
|
|
|
if video_file: |
|
|
|
tfile = tempfile.NamedTemporaryFile(delete=False) |
|
tfile.write(video_file.read()) |
|
|
|
|
|
st.video(tfile.name) |
|
|
|
|
|
if st.button("Analyze Dog Behavior"): |
|
with st.spinner("Analyzing your dog's behavior..."): |
|
|
|
time.sleep(2) |
|
|
|
|
|
results = interpreter.analyze_video(tfile.name) |
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
with col1: |
|
st.subheader("Primary Emotion") |
|
st.info(results['primary_emotion']) |
|
st.metric("Confidence", f"{results['confidence']*100:.1f}%") |
|
|
|
with col2: |
|
st.subheader("Actions Detected") |
|
for action in results['actions_detected']: |
|
st.success(action.replace('_', ' ').title()) |
|
|
|
|
|
st.subheader("Recommendations") |
|
for rec in results['recommendations']: |
|
st.write("β’ " + rec) |
|
|
|
|
|
with st.expander("About Dog Body Language"): |
|
st.markdown(""" |
|
### Common Dog Behaviors and Their Meanings: |
|
- **Tail Wagging**: Usually indicates happiness, but the position matters |
|
- **Ears Position**: Can show alertness, submission, or aggression |
|
- **Body Posture**: Reveals confidence or anxiety levels |
|
- **Facial Expressions**: Can indicate stress, happiness, or attention |
|
|
|
Remember that each dog is unique and may express emotions differently! |
|
""") |
|
|
|
if __name__ == "__main__": |
|
main() |