File size: 8,073 Bytes
71779a0
82f6468
 
 
71779a0
 
29fa7a0
71779a0
 
82f6468
71779a0
 
82f6468
 
 
 
 
 
 
 
0fe4c49
 
82f6468
0fe4c49
 
 
82f6468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fe4c49
 
 
 
 
 
82f6468
 
 
 
 
 
 
 
 
 
 
 
 
0fe4c49
82f6468
 
 
0fe4c49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82f6468
 
 
 
 
0fe4c49
 
 
 
 
 
 
82f6468
 
 
 
 
 
 
0fe4c49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82f6468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
---
title: Athletic Ability Analysis
emoji: πŸƒβ€β™‚οΈ
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.32.2
app_file: app.py
pinned: false
license: mit
---

# πŸƒβ€β™‚οΈ Athletic Ability Analysis

A powerful web application that analyzes athletic jump performance from videos using computer vision and pose estimation. Upload a video file or provide a YouTube URL to get detailed metrics about your jump height, flight time, and overall athletic performance.

## ✨ Features

- **πŸŽ₯ YouTube Integration**: Analyze videos directly from YouTube URLs
- **πŸ“ File Upload**: Support for MP4, AVI, MOV, and other video formats  
- **πŸ“Š Comprehensive Biomechanical Analysis**: Jump height, flight time, peak power, force development, and more
- **πŸ€– AI Sports Coach**: Get personalized sport recommendations and technique improvements
- **🎯 Real-time Processing**: Fast analysis using Google's MediaPipe pose estimation
- **πŸ“± Modern Interface**: Beautiful, responsive Gradio interface with multiple analysis modes
- **πŸ”¬ Scientific Accuracy**: Professional-grade biomechanical analysis
- **⚑ Advanced Metrics**: Peak power output, rate of force development, impulse, and ground contact time

## πŸš€ Live Demo

Try the live demo on Hugging Face Spaces: [Athletic Ability Analysis](https://huggingface.co/spaces/YOUR_USERNAME/athletic-ability-analysis)

## πŸ“Š How It Works

1. **Pose Detection**: Uses Google's MediaPipe to detect human pose landmarks in each video frame
2. **Hip Tracking**: Tracks the midpoint between left and right hip joints throughout the video
3. **Jump Analysis**: Calculates jump metrics based on hip trajectory:
   - **Jump Height**: Vertical distance from crouch to apex (in cm)
   - **Flight Time**: Duration of airborne phase (in seconds)
   - **Normalized Rise**: Jump height relative to body position (0-1 scale)
   - **Performance Insights**: Contextual feedback based on performance level

## πŸ› οΈ Technology Stack

- **Backend**: Python with OpenCV, NumPy, and MediaPipe
- **Frontend**: Gradio for beautiful, interactive web interface
- **Video Processing**: yt-dlp for YouTube downloads, OpenCV for video analysis
- **Deployment**: Hugging Face Spaces

## πŸš€ Deploy to Hugging Face Spaces

### Quick Deployment

1. **Fork this repository** on GitHub
2. **Create a new Space** on [Hugging Face Spaces](https://huggingface.co/spaces)
3. **Connect your GitHub repo** to the Space
4. **Set the Space type** to "Gradio"
5. **⚠️ IMPORTANT: Set up API Key Environment Variable**:
   - Go to your Space's "Settings" tab
   - Add a new "Secret" with name: `GEMINI_API_KEY`
   - Add your Gemini API key as the value
   - This keeps your API key secure and private
6. **Wait for automatic deployment**

### Manual Deployment

1. **Clone the repository**:
   ```bash
   git clone https://github.com/YOUR_USERNAME/athletic-ability-analysis
   cd athletic-ability-analysis
   ```

2. **Create a new Space** on Hugging Face Spaces

3. **Upload files** to your Space:
   - `app.py` (main application)
   - `athletic_performance.py` (analysis module)
   - `requirements.txt` (dependencies)
   - `README.md` (this file)

4. **πŸ” Set up Secure API Key**:
   - In your Space settings, add environment variable: `GEMINI_API_KEY`
   - Get your free API key from [Google AI Studio](https://aistudio.google.com/app/apikey)
   - **NEVER commit API keys to your repository!**

5. **Space will automatically deploy** using Gradio

### πŸ” API Key Security

For the AI Sports Coach feature, you need a Google Gemini API key:

- **πŸ†“ Free**: Get your key at [Google AI Studio](https://aistudio.google.com/app/apikey)
- **πŸ”’ Secure**: Set as environment variable `GEMINI_API_KEY` in HF Spaces
- **🚫 Never**: Commit API keys to code repositories
- **βœ… Best Practice**: Use HF Spaces secrets for deployment

## πŸ“ Project Structure

```
athletic-ability-analysis/
β”œβ”€β”€ app.py                    # Main Gradio application & UI
β”œβ”€β”€ athletic_performance.py   # Core analysis & AI integration
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ README.md                # This file (with HF Spaces header)
β”œβ”€β”€ deploy_hf.py             # Deployment helper script
β”œβ”€β”€ test_deployment.py       # Dependency testing
└── .gitignore              # Git ignore file
```

## 🎯 Usage

### Web Interface

1. **Visit your Hugging Face Space URL**
2. **Enter your height and weight** for accurate biomechanical calculations
3. **Choose your analysis type**:
   
   **πŸ“Š Standard Analysis:**
   - YouTube or File Upload tabs
   - Get comprehensive biomechanical metrics
   
   **πŸ€– AI Sports Coach:**
   - Select your gender
   - Provide video (YouTube URL or upload)
   - Get personalized sport recommendations
   - Receive jump technique improvement suggestions

4. **Click analyze** and wait for processing
5. **View comprehensive results** with detailed insights

### Supported Video Formats

- **YouTube**: Any public YouTube video URL
- **Upload**: MP4, AVI, MOV, MKV, WebM

## πŸ“ Video Requirements

For optimal results, ensure your videos meet these criteria:

- **🎯 Full Body Visible**: Person should be completely visible throughout the jump
- **πŸ’‘ Good Lighting**: Clear visibility with minimal shadows
- **🎬 Clean Background**: Minimal clutter for better pose detection
- **⏱️ Optimal Duration**: 3-30 seconds works best
- **πŸ“ Vertical Jumps**: Straight vertical jumps produce most accurate results
- **πŸ”“ Public Access**: For YouTube videos, ensure they're not private

## πŸ“Š Performance Metrics

The app analyzes and provides:

- **Jump Height (cm)**: Absolute vertical distance based on your body height
- **Flight Time (s)**: Duration of airborne phase
- **Normalized Rise**: Jump efficiency relative to body size
- **Performance Level**: Contextual feedback (Excellent/Good/Moderate/Starting)
- **Training Insights**: Personalized recommendations

## πŸ”¬ Technical Details

- **Pose Estimation**: MediaPipe Pose with 33 body landmarks
- **Processing**: Real-time frame-by-frame analysis
- **Smoothing**: Moving average filtering for noise reduction
- **Calculations**: Biomechanically accurate jump metrics
- **Performance**: Optimized for cloud deployment

## ⚠️ Limitations

- **Processing Time**: Large videos may take 2-5 minutes to process
- **File Size**: Recommended maximum 100MB for uploads
- **Pose Visibility**: Person must be clearly visible throughout the jump
- **Jump Type**: Optimized for vertical jumps (not broad jumps)

## πŸ”§ Local Development

To run locally:

1. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

2. **Run the application**:
   ```bash
   python app.py
   ```

3. **Open in browser**: Gradio will provide a local URL

## 🀝 Contributing

Contributions are welcome! Please feel free to:

- Submit bug reports and feature requests
- Improve documentation
- Add new analysis features
- Optimize performance

## πŸ“„ License

This project is open source and available under the [MIT License](LICENSE).

## πŸ†˜ Support & Troubleshooting

If you encounter issues:

1. **Video Quality**: Ensure good lighting and clear visibility
2. **YouTube URLs**: Make sure the video is public and accessible
3. **File Formats**: Use supported video formats (MP4, AVI, MOV, etc.)
4. **Processing Time**: Be patient with large or high-resolution videos
5. **Pose Detection**: Person should be fully visible during the jump

## πŸ™ Acknowledgments

- **Google MediaPipe** for state-of-the-art pose estimation
- **OpenCV** for computer vision processing
- **yt-dlp** for YouTube video downloading
- **Gradio** for the beautiful web interface
- **Hugging Face** for hosting and deployment platform

## πŸ“ˆ Example Results

```
πŸŽ‰ Jump Analysis Results

πŸ“Š Performance Metrics
- Jump Height: 52.34 cm
- Flight Time: 0.623 seconds  
- Normalized Rise: 0.387 (38.7%)

πŸ”₯ Excellent jump height! This is above average performance.
⏱️ Great flight time! Shows good explosive power.
```