Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- README.md +189 -6
- app.py +410 -0
- deploy_hf.py +122 -0
- requirements.txt +6 -0
README.md
CHANGED
|
@@ -1,13 +1,196 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Athletic Ability Analysis
|
| 3 |
+
emoji: πββοΈ
|
| 4 |
+
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.7.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# πββοΈ Athletic Ability Analysis
|
| 14 |
+
|
| 15 |
+
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.
|
| 16 |
+
|
| 17 |
+
## β¨ Features
|
| 18 |
+
|
| 19 |
+
- **π₯ YouTube Integration**: Analyze videos directly from YouTube URLs
|
| 20 |
+
- **π File Upload**: Support for MP4, AVI, MOV, and other video formats
|
| 21 |
+
- **π Detailed Analytics**: Get jump height, flight time, normalized rise, and performance insights
|
| 22 |
+
- **π― Real-time Processing**: Fast analysis using Google's MediaPipe pose estimation
|
| 23 |
+
- **π± Modern Interface**: Beautiful, responsive Gradio interface
|
| 24 |
+
- **π¬ Scientific Accuracy**: Precise biomechanical analysis
|
| 25 |
+
|
| 26 |
+
## π Live Demo
|
| 27 |
+
|
| 28 |
+
Try the live demo on Hugging Face Spaces: [Athletic Ability Analysis](https://huggingface.co/spaces/YOUR_USERNAME/athletic-ability-analysis)
|
| 29 |
+
|
| 30 |
+
## π How It Works
|
| 31 |
+
|
| 32 |
+
1. **Pose Detection**: Uses Google's MediaPipe to detect human pose landmarks in each video frame
|
| 33 |
+
2. **Hip Tracking**: Tracks the midpoint between left and right hip joints throughout the video
|
| 34 |
+
3. **Jump Analysis**: Calculates jump metrics based on hip trajectory:
|
| 35 |
+
- **Jump Height**: Vertical distance from crouch to apex (in cm)
|
| 36 |
+
- **Flight Time**: Duration of airborne phase (in seconds)
|
| 37 |
+
- **Normalized Rise**: Jump height relative to body position (0-1 scale)
|
| 38 |
+
- **Performance Insights**: Contextual feedback based on performance level
|
| 39 |
+
|
| 40 |
+
## π οΈ Technology Stack
|
| 41 |
+
|
| 42 |
+
- **Backend**: Python with OpenCV, NumPy, and MediaPipe
|
| 43 |
+
- **Frontend**: Gradio for beautiful, interactive web interface
|
| 44 |
+
- **Video Processing**: yt-dlp for YouTube downloads, OpenCV for video analysis
|
| 45 |
+
- **Deployment**: Hugging Face Spaces
|
| 46 |
+
|
| 47 |
+
## π Deploy to Hugging Face Spaces
|
| 48 |
+
|
| 49 |
+
### Quick Deployment
|
| 50 |
+
|
| 51 |
+
1. **Fork this repository** on GitHub
|
| 52 |
+
2. **Create a new Space** on [Hugging Face Spaces](https://huggingface.co/spaces)
|
| 53 |
+
3. **Connect your GitHub repo** to the Space
|
| 54 |
+
4. **Set the Space type** to "Gradio"
|
| 55 |
+
5. **Wait for automatic deployment**
|
| 56 |
+
|
| 57 |
+
### Manual Deployment
|
| 58 |
+
|
| 59 |
+
1. **Clone the repository**:
|
| 60 |
+
```bash
|
| 61 |
+
git clone https://github.com/YOUR_USERNAME/athletic-ability-analysis
|
| 62 |
+
cd athletic-ability-analysis
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
2. **Create a new Space** on Hugging Face Spaces
|
| 66 |
+
|
| 67 |
+
3. **Upload files** to your Space:
|
| 68 |
+
- `app.py` (main application)
|
| 69 |
+
- `requirements.txt` (dependencies)
|
| 70 |
+
- `README.md` (this file)
|
| 71 |
+
|
| 72 |
+
4. **Space will automatically deploy** using Gradio
|
| 73 |
+
|
| 74 |
+
## π Project Structure
|
| 75 |
+
|
| 76 |
+
```
|
| 77 |
+
athletic-ability-analysis/
|
| 78 |
+
βββ app.py # Main Gradio application
|
| 79 |
+
βββ requirements.txt # Python dependencies
|
| 80 |
+
βββ README.md # This file (with HF Spaces header)
|
| 81 |
+
βββ .gitignore # Git ignore file
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## π― Usage
|
| 85 |
+
|
| 86 |
+
### Web Interface
|
| 87 |
+
|
| 88 |
+
1. **Visit your Hugging Face Space URL**
|
| 89 |
+
2. **Enter your height** in centimeters for accurate calculations
|
| 90 |
+
3. **Choose input method**:
|
| 91 |
+
- **YouTube**: Paste a YouTube URL containing a jump video
|
| 92 |
+
- **File Upload**: Upload a video file from your device
|
| 93 |
+
4. **Click "Analyze"** and wait for processing
|
| 94 |
+
5. **View detailed results** including metrics and performance insights
|
| 95 |
+
|
| 96 |
+
### Supported Video Formats
|
| 97 |
+
|
| 98 |
+
- **YouTube**: Any public YouTube video URL
|
| 99 |
+
- **Upload**: MP4, AVI, MOV, MKV, WebM
|
| 100 |
+
|
| 101 |
+
## π Video Requirements
|
| 102 |
+
|
| 103 |
+
For optimal results, ensure your videos meet these criteria:
|
| 104 |
+
|
| 105 |
+
- **π― Full Body Visible**: Person should be completely visible throughout the jump
|
| 106 |
+
- **π‘ Good Lighting**: Clear visibility with minimal shadows
|
| 107 |
+
- **π¬ Clean Background**: Minimal clutter for better pose detection
|
| 108 |
+
- **β±οΈ Optimal Duration**: 3-30 seconds works best
|
| 109 |
+
- **π Vertical Jumps**: Straight vertical jumps produce most accurate results
|
| 110 |
+
- **π Public Access**: For YouTube videos, ensure they're not private
|
| 111 |
+
|
| 112 |
+
## π Performance Metrics
|
| 113 |
+
|
| 114 |
+
The app analyzes and provides:
|
| 115 |
+
|
| 116 |
+
- **Jump Height (cm)**: Absolute vertical distance based on your body height
|
| 117 |
+
- **Flight Time (s)**: Duration of airborne phase
|
| 118 |
+
- **Normalized Rise**: Jump efficiency relative to body size
|
| 119 |
+
- **Performance Level**: Contextual feedback (Excellent/Good/Moderate/Starting)
|
| 120 |
+
- **Training Insights**: Personalized recommendations
|
| 121 |
+
|
| 122 |
+
## π¬ Technical Details
|
| 123 |
+
|
| 124 |
+
- **Pose Estimation**: MediaPipe Pose with 33 body landmarks
|
| 125 |
+
- **Processing**: Real-time frame-by-frame analysis
|
| 126 |
+
- **Smoothing**: Moving average filtering for noise reduction
|
| 127 |
+
- **Calculations**: Biomechanically accurate jump metrics
|
| 128 |
+
- **Performance**: Optimized for cloud deployment
|
| 129 |
+
|
| 130 |
+
## β οΈ Limitations
|
| 131 |
+
|
| 132 |
+
- **Processing Time**: Large videos may take 2-5 minutes to process
|
| 133 |
+
- **File Size**: Recommended maximum 100MB for uploads
|
| 134 |
+
- **Pose Visibility**: Person must be clearly visible throughout the jump
|
| 135 |
+
- **Jump Type**: Optimized for vertical jumps (not broad jumps)
|
| 136 |
+
|
| 137 |
+
## π§ Local Development
|
| 138 |
+
|
| 139 |
+
To run locally:
|
| 140 |
+
|
| 141 |
+
1. **Install dependencies**:
|
| 142 |
+
```bash
|
| 143 |
+
pip install -r requirements.txt
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
2. **Run the application**:
|
| 147 |
+
```bash
|
| 148 |
+
python app.py
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
3. **Open in browser**: Gradio will provide a local URL
|
| 152 |
+
|
| 153 |
+
## π€ Contributing
|
| 154 |
+
|
| 155 |
+
Contributions are welcome! Please feel free to:
|
| 156 |
+
|
| 157 |
+
- Submit bug reports and feature requests
|
| 158 |
+
- Improve documentation
|
| 159 |
+
- Add new analysis features
|
| 160 |
+
- Optimize performance
|
| 161 |
+
|
| 162 |
+
## π License
|
| 163 |
+
|
| 164 |
+
This project is open source and available under the [MIT License](LICENSE).
|
| 165 |
+
|
| 166 |
+
## π Support & Troubleshooting
|
| 167 |
+
|
| 168 |
+
If you encounter issues:
|
| 169 |
+
|
| 170 |
+
1. **Video Quality**: Ensure good lighting and clear visibility
|
| 171 |
+
2. **YouTube URLs**: Make sure the video is public and accessible
|
| 172 |
+
3. **File Formats**: Use supported video formats (MP4, AVI, MOV, etc.)
|
| 173 |
+
4. **Processing Time**: Be patient with large or high-resolution videos
|
| 174 |
+
5. **Pose Detection**: Person should be fully visible during the jump
|
| 175 |
+
|
| 176 |
+
## π Acknowledgments
|
| 177 |
+
|
| 178 |
+
- **Google MediaPipe** for state-of-the-art pose estimation
|
| 179 |
+
- **OpenCV** for computer vision processing
|
| 180 |
+
- **yt-dlp** for YouTube video downloading
|
| 181 |
+
- **Gradio** for the beautiful web interface
|
| 182 |
+
- **Hugging Face** for hosting and deployment platform
|
| 183 |
+
|
| 184 |
+
## π Example Results
|
| 185 |
+
|
| 186 |
+
```
|
| 187 |
+
π Jump Analysis Results
|
| 188 |
+
|
| 189 |
+
π Performance Metrics
|
| 190 |
+
- Jump Height: 52.34 cm
|
| 191 |
+
- Flight Time: 0.623 seconds
|
| 192 |
+
- Normalized Rise: 0.387 (38.7%)
|
| 193 |
+
|
| 194 |
+
π₯ Excellent jump height! This is above average performance.
|
| 195 |
+
β±οΈ Great flight time! Shows good explosive power.
|
| 196 |
+
```
|
app.py
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
import mediapipe as mp
|
| 4 |
+
from collections import deque
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import json
|
| 7 |
+
import tempfile
|
| 8 |
+
import os
|
| 9 |
+
import yt_dlp
|
| 10 |
+
import gradio as gr
|
| 11 |
+
import pandas as pd
|
| 12 |
+
|
| 13 |
+
LHIP, RHIP = 23, 24
|
| 14 |
+
POSE_CONNECTIONS = mp.solutions.pose.POSE_CONNECTIONS
|
| 15 |
+
|
| 16 |
+
def smooth_moving_avg(series, k=5):
|
| 17 |
+
"""Simple causal moving average; ignores None values."""
|
| 18 |
+
out = []
|
| 19 |
+
q = deque()
|
| 20 |
+
s = 0.0
|
| 21 |
+
cnt = 0
|
| 22 |
+
for v in series:
|
| 23 |
+
if v is not None:
|
| 24 |
+
q.append(v); s += v; cnt += 1
|
| 25 |
+
else:
|
| 26 |
+
q.append(None)
|
| 27 |
+
if len(q) > k:
|
| 28 |
+
old = q.popleft()
|
| 29 |
+
if old is not None:
|
| 30 |
+
s -= old; cnt -= 1
|
| 31 |
+
out.append((s / max(cnt, 1)) if cnt > 0 else None)
|
| 32 |
+
return out
|
| 33 |
+
|
| 34 |
+
def estimate_jump_metrics(hip_y_series, fps):
|
| 35 |
+
"""Return jump_height_norm (0..1), flight_time_s using hip trajectory."""
|
| 36 |
+
# Remove None
|
| 37 |
+
hip = [h for h in hip_y_series if h is not None]
|
| 38 |
+
if len(hip) < 3:
|
| 39 |
+
return None, None
|
| 40 |
+
|
| 41 |
+
# Smooth
|
| 42 |
+
hip = smooth_moving_avg(hip, k=5)
|
| 43 |
+
|
| 44 |
+
# Jump height (normalized): deepest crouch (max y) to apex (min y)
|
| 45 |
+
min_y = min(hip) # apex (body highest)
|
| 46 |
+
max_y = max(hip) # deepest crouch (body lowest)
|
| 47 |
+
jump_height_norm = max(0.0, (max_y - min_y))
|
| 48 |
+
|
| 49 |
+
# Flight time heuristic using vertical velocity pattern
|
| 50 |
+
hip_arr = np.array(hip, dtype=float)
|
| 51 |
+
vel = np.diff(hip_arr)
|
| 52 |
+
if vel.size == 0:
|
| 53 |
+
flight_time_s = 0.0
|
| 54 |
+
else:
|
| 55 |
+
takeoff_idx = int(np.argmin(vel)) # most negative velocity
|
| 56 |
+
landing_idx = int(np.argmax(vel)) # most positive velocity
|
| 57 |
+
flight_frames = max(0, landing_idx - takeoff_idx)
|
| 58 |
+
flight_time_s = flight_frames / float(fps or 30.0)
|
| 59 |
+
|
| 60 |
+
return jump_height_norm, flight_time_s
|
| 61 |
+
|
| 62 |
+
def download_youtube_video(youtube_url, output_path):
|
| 63 |
+
"""Download YouTube video to specified path."""
|
| 64 |
+
ydl_opts = {
|
| 65 |
+
'format': 'best[height<=720]', # Limit quality for faster processing
|
| 66 |
+
'outtmpl': output_path,
|
| 67 |
+
'quiet': True,
|
| 68 |
+
'no_warnings': True,
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 72 |
+
ydl.download([youtube_url])
|
| 73 |
+
return output_path
|
| 74 |
+
|
| 75 |
+
def process_video_analysis(video_path, user_height_cm, progress_callback=None):
|
| 76 |
+
"""Core video analysis function with progress tracking."""
|
| 77 |
+
cap = cv2.VideoCapture(video_path)
|
| 78 |
+
if not cap.isOpened():
|
| 79 |
+
raise Exception(f"Could not open video: {video_path}")
|
| 80 |
+
|
| 81 |
+
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 82 |
+
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 83 |
+
fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
|
| 84 |
+
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 85 |
+
|
| 86 |
+
mp_pose = mp.solutions.pose
|
| 87 |
+
pose = mp_pose.Pose(static_image_mode=False, model_complexity=1, enable_segmentation=False)
|
| 88 |
+
|
| 89 |
+
hip_y_series = []
|
| 90 |
+
frame_idx = 0
|
| 91 |
+
|
| 92 |
+
print(f"Processing video: {Path(video_path).name}")
|
| 93 |
+
print(f"Video dimensions: {w}x{h}, FPS: {fps}, Total frames: {total_frames}")
|
| 94 |
+
|
| 95 |
+
ok, frame = cap.read()
|
| 96 |
+
while ok:
|
| 97 |
+
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 98 |
+
res = pose.process(rgb)
|
| 99 |
+
|
| 100 |
+
if res.pose_landmarks:
|
| 101 |
+
lms = res.pose_landmarks.landmark
|
| 102 |
+
mid_hip_y = (lms[LHIP].y + lms[RHIP].y) / 2.0
|
| 103 |
+
hip_y_series.append(float(mid_hip_y))
|
| 104 |
+
else:
|
| 105 |
+
hip_y_series.append(None)
|
| 106 |
+
|
| 107 |
+
frame_idx += 1
|
| 108 |
+
|
| 109 |
+
# Update progress
|
| 110 |
+
if progress_callback and total_frames > 0:
|
| 111 |
+
progress = min(frame_idx / total_frames, 1.0)
|
| 112 |
+
progress_callback(progress, f"Processing frame {frame_idx}/{total_frames}")
|
| 113 |
+
|
| 114 |
+
ok, frame = cap.read()
|
| 115 |
+
|
| 116 |
+
cap.release()
|
| 117 |
+
print(f"Completed processing {frame_idx} frames")
|
| 118 |
+
|
| 119 |
+
jump_norm, flight_time_s = estimate_jump_metrics(hip_y_series, fps)
|
| 120 |
+
|
| 121 |
+
if jump_norm is None:
|
| 122 |
+
return None
|
| 123 |
+
|
| 124 |
+
jump_height_cm = jump_norm * user_height_cm
|
| 125 |
+
|
| 126 |
+
return {
|
| 127 |
+
"video": Path(video_path).name,
|
| 128 |
+
"frames": len(hip_y_series),
|
| 129 |
+
"fps": fps,
|
| 130 |
+
"jump_height_cm": jump_height_cm,
|
| 131 |
+
"normalized_rise": jump_norm,
|
| 132 |
+
"flight_time_s": flight_time_s
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
def analyze_jump_from_youtube(youtube_url, user_height_cm, progress=gr.Progress()):
|
| 136 |
+
"""Main analysis function for Gradio interface."""
|
| 137 |
+
|
| 138 |
+
# Validate inputs
|
| 139 |
+
if not youtube_url or not youtube_url.strip():
|
| 140 |
+
return "β Please provide a YouTube URL", None, None
|
| 141 |
+
|
| 142 |
+
if not user_height_cm or user_height_cm <= 0:
|
| 143 |
+
return "β Please provide a valid height in centimeters", None, None
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
progress(0.1, desc="Validating YouTube URL...")
|
| 147 |
+
|
| 148 |
+
# Validate YouTube URL
|
| 149 |
+
youtube_url = youtube_url.strip()
|
| 150 |
+
if not any(domain in youtube_url for domain in ['youtube.com', 'youtu.be']):
|
| 151 |
+
return "β Please provide a valid YouTube URL", None, None
|
| 152 |
+
|
| 153 |
+
# Create temporary directory for processing
|
| 154 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 155 |
+
progress(0.2, desc="Downloading video from YouTube...")
|
| 156 |
+
|
| 157 |
+
# Download video
|
| 158 |
+
video_filename = os.path.join(temp_dir, 'video.%(ext)s')
|
| 159 |
+
try:
|
| 160 |
+
download_youtube_video(youtube_url, video_filename)
|
| 161 |
+
# Find the actual downloaded file
|
| 162 |
+
video_files = [f for f in os.listdir(temp_dir) if f.startswith('video.')]
|
| 163 |
+
if not video_files:
|
| 164 |
+
return "β Failed to download YouTube video. Please check the URL and try again.", None, None
|
| 165 |
+
video_path = os.path.join(temp_dir, video_files[0])
|
| 166 |
+
except Exception as e:
|
| 167 |
+
return f"β Failed to download YouTube video: {str(e)}", None, None
|
| 168 |
+
|
| 169 |
+
progress(0.3, desc="Starting video analysis...")
|
| 170 |
+
|
| 171 |
+
# Process the video with progress tracking
|
| 172 |
+
def update_progress(prog, desc):
|
| 173 |
+
progress(0.3 + (prog * 0.6), desc=desc)
|
| 174 |
+
|
| 175 |
+
result = process_video_analysis(video_path, user_height_cm, update_progress)
|
| 176 |
+
|
| 177 |
+
progress(0.9, desc="Generating results...")
|
| 178 |
+
|
| 179 |
+
if result is None:
|
| 180 |
+
return "β οΈ Could not analyze jump. Make sure the video shows a person clearly performing a vertical jump.", None, None
|
| 181 |
+
|
| 182 |
+
# Format results for display
|
| 183 |
+
results_text = f"""
|
| 184 |
+
## π Jump Analysis Results
|
| 185 |
+
|
| 186 |
+
### π Performance Metrics
|
| 187 |
+
- **Jump Height**: {result['jump_height_cm']:.2f} cm
|
| 188 |
+
- **Flight Time**: {result['flight_time_s']:.3f} seconds
|
| 189 |
+
- **Normalized Rise**: {result['normalized_rise']:.3f} ({result['normalized_rise']*100:.1f}%)
|
| 190 |
+
|
| 191 |
+
### πΉ Video Information
|
| 192 |
+
- **Total Frames**: {result['frames']}
|
| 193 |
+
- **Frame Rate**: {result['fps']:.2f} FPS
|
| 194 |
+
- **Video File**: {result['video']}
|
| 195 |
+
|
| 196 |
+
### π Performance Insights
|
| 197 |
+
"""
|
| 198 |
+
|
| 199 |
+
# Add performance insights
|
| 200 |
+
if result['jump_height_cm'] > 60:
|
| 201 |
+
results_text += "π₯ **Excellent jump height!** This is above average performance.\n"
|
| 202 |
+
elif result['jump_height_cm'] > 40:
|
| 203 |
+
results_text += "π **Good jump height!** Solid athletic performance.\n"
|
| 204 |
+
elif result['jump_height_cm'] > 25:
|
| 205 |
+
results_text += "π **Moderate jump height.** Room for improvement with training.\n"
|
| 206 |
+
else:
|
| 207 |
+
results_text += "π― **Starting point identified.** Focus on technique and strength training.\n"
|
| 208 |
+
|
| 209 |
+
if result['flight_time_s'] > 0.5:
|
| 210 |
+
results_text += "β±οΈ **Great flight time!** Shows good explosive power.\n"
|
| 211 |
+
elif result['flight_time_s'] > 0.3:
|
| 212 |
+
results_text += "β±οΈ **Decent flight time.** Good coordination.\n"
|
| 213 |
+
|
| 214 |
+
# Create a results dataframe for the table
|
| 215 |
+
results_df = pd.DataFrame([
|
| 216 |
+
["Jump Height", f"{result['jump_height_cm']:.2f} cm"],
|
| 217 |
+
["Flight Time", f"{result['flight_time_s']:.3f} seconds"],
|
| 218 |
+
["Normalized Rise", f"{result['normalized_rise']*100:.1f}%"],
|
| 219 |
+
["Video Frames", f"{result['frames']}"],
|
| 220 |
+
["Frame Rate", f"{result['fps']:.2f} FPS"],
|
| 221 |
+
], columns=["Metric", "Value"])
|
| 222 |
+
|
| 223 |
+
progress(1.0, desc="Analysis complete!")
|
| 224 |
+
|
| 225 |
+
return results_text, results_df, "β
Analysis completed successfully!"
|
| 226 |
+
|
| 227 |
+
except Exception as e:
|
| 228 |
+
return f"β Error during analysis: {str(e)}", None, None
|
| 229 |
+
|
| 230 |
+
def analyze_jump_from_file(video_file, user_height_cm, progress=gr.Progress()):
|
| 231 |
+
"""Analysis function for uploaded video files."""
|
| 232 |
+
|
| 233 |
+
# Validate inputs
|
| 234 |
+
if video_file is None:
|
| 235 |
+
return "β Please upload a video file", None, None
|
| 236 |
+
|
| 237 |
+
if not user_height_cm or user_height_cm <= 0:
|
| 238 |
+
return "β Please provide a valid height in centimeters", None, None
|
| 239 |
+
|
| 240 |
+
try:
|
| 241 |
+
progress(0.1, desc="Processing uploaded video...")
|
| 242 |
+
|
| 243 |
+
# Process the video with progress tracking
|
| 244 |
+
def update_progress(prog, desc):
|
| 245 |
+
progress(0.1 + (prog * 0.8), desc=desc)
|
| 246 |
+
|
| 247 |
+
result = process_video_analysis(video_file.name, user_height_cm, update_progress)
|
| 248 |
+
|
| 249 |
+
progress(0.9, desc="Generating results...")
|
| 250 |
+
|
| 251 |
+
if result is None:
|
| 252 |
+
return "β οΈ Could not analyze jump. Make sure the video shows a person clearly performing a vertical jump.", None, None
|
| 253 |
+
|
| 254 |
+
# Format results (same as YouTube function)
|
| 255 |
+
results_text = f"""
|
| 256 |
+
## π Jump Analysis Results
|
| 257 |
+
|
| 258 |
+
### π Performance Metrics
|
| 259 |
+
- **Jump Height**: {result['jump_height_cm']:.2f} cm
|
| 260 |
+
- **Flight Time**: {result['flight_time_s']:.3f} seconds
|
| 261 |
+
- **Normalized Rise**: {result['normalized_rise']:.3f} ({result['normalized_rise']*100:.1f}%)
|
| 262 |
+
|
| 263 |
+
### πΉ Video Information
|
| 264 |
+
- **Total Frames**: {result['frames']}
|
| 265 |
+
- **Frame Rate**: {result['fps']:.2f} FPS
|
| 266 |
+
- **Video File**: {result['video']}
|
| 267 |
+
|
| 268 |
+
### π Performance Insights
|
| 269 |
+
"""
|
| 270 |
+
|
| 271 |
+
# Add performance insights
|
| 272 |
+
if result['jump_height_cm'] > 60:
|
| 273 |
+
results_text += "π₯ **Excellent jump height!** This is above average performance.\n"
|
| 274 |
+
elif result['jump_height_cm'] > 40:
|
| 275 |
+
results_text += "π **Good jump height!** Solid athletic performance.\n"
|
| 276 |
+
elif result['jump_height_cm'] > 25:
|
| 277 |
+
results_text += "π **Moderate jump height.** Room for improvement with training.\n"
|
| 278 |
+
else:
|
| 279 |
+
results_text += "π― **Starting point identified.** Focus on technique and strength training.\n"
|
| 280 |
+
|
| 281 |
+
if result['flight_time_s'] > 0.5:
|
| 282 |
+
results_text += "β±οΈ **Great flight time!** Shows good explosive power.\n"
|
| 283 |
+
elif result['flight_time_s'] > 0.3:
|
| 284 |
+
results_text += "β±οΈ **Decent flight time.** Good coordination.\n"
|
| 285 |
+
|
| 286 |
+
# Create a results dataframe for the table
|
| 287 |
+
results_df = pd.DataFrame([
|
| 288 |
+
["Jump Height", f"{result['jump_height_cm']:.2f} cm"],
|
| 289 |
+
["Flight Time", f"{result['flight_time_s']:.3f} seconds"],
|
| 290 |
+
["Normalized Rise", f"{result['normalized_rise']*100:.1f}%"],
|
| 291 |
+
["Video Frames", f"{result['frames']}"],
|
| 292 |
+
["Frame Rate", f"{result['fps']:.2f} FPS"],
|
| 293 |
+
], columns=["Metric", "Value"])
|
| 294 |
+
|
| 295 |
+
progress(1.0, desc="Analysis complete!")
|
| 296 |
+
|
| 297 |
+
return results_text, results_df, "β
Analysis completed successfully!"
|
| 298 |
+
|
| 299 |
+
except Exception as e:
|
| 300 |
+
return f"β Error during analysis: {str(e)}", None, None
|
| 301 |
+
|
| 302 |
+
# Create Gradio interface
|
| 303 |
+
def create_interface():
|
| 304 |
+
with gr.Blocks(title="πββοΈ Athletic Ability Analysis", theme=gr.themes.Soft()) as app:
|
| 305 |
+
gr.Markdown("""
|
| 306 |
+
# πββοΈ Athletic Ability Analysis
|
| 307 |
+
|
| 308 |
+
Analyze jumping performance from videos using computer vision and pose estimation.
|
| 309 |
+
Upload a video or provide a YouTube URL to get detailed metrics about jump height, flight time, and athletic performance.
|
| 310 |
+
|
| 311 |
+
## π Instructions
|
| 312 |
+
1. Enter your height in centimeters
|
| 313 |
+
2. Choose either YouTube URL or file upload
|
| 314 |
+
3. Wait for the analysis to complete
|
| 315 |
+
4. View your detailed jump performance results
|
| 316 |
+
""")
|
| 317 |
+
|
| 318 |
+
with gr.Row():
|
| 319 |
+
user_height = gr.Number(
|
| 320 |
+
label="Your Height (cm)",
|
| 321 |
+
value=175,
|
| 322 |
+
minimum=100,
|
| 323 |
+
maximum=250,
|
| 324 |
+
info="Enter your height in centimeters for accurate jump height calculation"
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
with gr.Tabs():
|
| 328 |
+
# YouTube URL Tab
|
| 329 |
+
with gr.TabItem("π₯ YouTube Video"):
|
| 330 |
+
youtube_url = gr.Textbox(
|
| 331 |
+
label="YouTube URL",
|
| 332 |
+
placeholder="https://youtube.com/watch?v=...",
|
| 333 |
+
info="Paste a YouTube URL containing a video of someone jumping"
|
| 334 |
+
)
|
| 335 |
+
youtube_btn = gr.Button("π Analyze YouTube Video", variant="primary", size="lg")
|
| 336 |
+
|
| 337 |
+
# File Upload Tab
|
| 338 |
+
with gr.TabItem("π Upload Video"):
|
| 339 |
+
video_file = gr.File(
|
| 340 |
+
label="Upload Video File",
|
| 341 |
+
file_types=[".mp4", ".avi", ".mov", ".mkv", ".webm"],
|
| 342 |
+
info="Upload a video file showing someone performing a jump"
|
| 343 |
+
)
|
| 344 |
+
file_btn = gr.Button("π Analyze Uploaded Video", variant="primary", size="lg")
|
| 345 |
+
|
| 346 |
+
# Results section
|
| 347 |
+
gr.Markdown("## π Analysis Results")
|
| 348 |
+
|
| 349 |
+
with gr.Row():
|
| 350 |
+
with gr.Column(scale=2):
|
| 351 |
+
results_text = gr.Markdown(label="Results")
|
| 352 |
+
with gr.Column(scale=1):
|
| 353 |
+
results_table = gr.Dataframe(
|
| 354 |
+
label="Metrics Summary",
|
| 355 |
+
headers=["Metric", "Value"],
|
| 356 |
+
datatype=["str", "str"]
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
status_message = gr.Textbox(label="Status", interactive=False)
|
| 360 |
+
|
| 361 |
+
# Video requirements
|
| 362 |
+
gr.Markdown("""
|
| 363 |
+
## π Video Requirements
|
| 364 |
+
|
| 365 |
+
For best results, ensure your videos meet these criteria:
|
| 366 |
+
|
| 367 |
+
- **Full body visible**: The person should be completely visible in the frame
|
| 368 |
+
- **Clear movement**: Good lighting and minimal background clutter
|
| 369 |
+
- **Vertical jumps**: Works best with straight vertical jumps
|
| 370 |
+
- **Duration**: 3-30 seconds is optimal
|
| 371 |
+
- **Quality**: Higher quality videos produce better results
|
| 372 |
+
- **Public videos**: For YouTube, ensure the video is not private
|
| 373 |
+
|
| 374 |
+
## π¬ How it Works
|
| 375 |
+
|
| 376 |
+
1. **Pose Detection**: Uses Google's MediaPipe to detect human pose landmarks
|
| 377 |
+
2. **Hip Tracking**: Tracks the midpoint between left and right hip joints
|
| 378 |
+
3. **Jump Analysis**: Calculates metrics based on hip trajectory:
|
| 379 |
+
- Jump height relative to your body size
|
| 380 |
+
- Flight time during the airborne phase
|
| 381 |
+
- Normalized rise showing jump efficiency
|
| 382 |
+
""")
|
| 383 |
+
|
| 384 |
+
# Event handlers
|
| 385 |
+
youtube_btn.click(
|
| 386 |
+
fn=analyze_jump_from_youtube,
|
| 387 |
+
inputs=[youtube_url, user_height],
|
| 388 |
+
outputs=[results_text, results_table, status_message]
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
file_btn.click(
|
| 392 |
+
fn=analyze_jump_from_file,
|
| 393 |
+
inputs=[video_file, user_height],
|
| 394 |
+
outputs=[results_text, results_table, status_message]
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
# Example section
|
| 398 |
+
gr.Examples(
|
| 399 |
+
examples=[
|
| 400 |
+
["https://www.youtube.com/watch?v=dQw4w9WgXcQ", 175], # This is just a placeholder
|
| 401 |
+
],
|
| 402 |
+
inputs=[youtube_url, user_height],
|
| 403 |
+
label="π Example (Replace with actual jump video URLs)"
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
return app
|
| 407 |
+
|
| 408 |
+
if __name__ == "__main__":
|
| 409 |
+
app = create_interface()
|
| 410 |
+
app.launch(debug=True, share=True)
|
deploy_hf.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Quick deployment script for Hugging Face Spaces
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
def run_command(cmd):
|
| 11 |
+
"""Run a shell command and return the result."""
|
| 12 |
+
try:
|
| 13 |
+
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
| 14 |
+
if result.returncode == 0:
|
| 15 |
+
return True, result.stdout
|
| 16 |
+
else:
|
| 17 |
+
return False, result.stderr
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return False, str(e)
|
| 20 |
+
|
| 21 |
+
def main():
|
| 22 |
+
print("πββοΈ Athletic Ability Analysis - Hugging Face Spaces Deployment")
|
| 23 |
+
print("=" * 70)
|
| 24 |
+
|
| 25 |
+
# Check if we're in the right directory
|
| 26 |
+
if not os.path.exists("app.py"):
|
| 27 |
+
print("β Error: app.py not found. Please run this script from the project root.")
|
| 28 |
+
sys.exit(1)
|
| 29 |
+
|
| 30 |
+
print("β
Found app.py")
|
| 31 |
+
|
| 32 |
+
# Check if requirements.txt exists
|
| 33 |
+
if not os.path.exists("requirements.txt"):
|
| 34 |
+
print("β Error: requirements.txt not found.")
|
| 35 |
+
sys.exit(1)
|
| 36 |
+
|
| 37 |
+
print("β
Found requirements.txt")
|
| 38 |
+
|
| 39 |
+
# Check if README.md has the HF header
|
| 40 |
+
try:
|
| 41 |
+
with open("README.md", "r") as f:
|
| 42 |
+
content = f.read()
|
| 43 |
+
if not content.startswith("---"):
|
| 44 |
+
print("β Error: README.md missing Hugging Face Spaces header")
|
| 45 |
+
print("π‘ The README should start with YAML frontmatter for HF Spaces")
|
| 46 |
+
sys.exit(1)
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
print("β Error: README.md not found.")
|
| 49 |
+
sys.exit(1)
|
| 50 |
+
|
| 51 |
+
print("β
README.md has correct HF Spaces format")
|
| 52 |
+
|
| 53 |
+
# Test if we can import the main dependencies
|
| 54 |
+
print("\nπ Testing dependencies...")
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
import gradio
|
| 58 |
+
print(f"β
Gradio {gradio.__version__}")
|
| 59 |
+
except ImportError:
|
| 60 |
+
print("β Gradio not installed. Run: pip install -r requirements.txt")
|
| 61 |
+
sys.exit(1)
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
import cv2
|
| 65 |
+
print("β
OpenCV")
|
| 66 |
+
except ImportError:
|
| 67 |
+
print("β OpenCV not installed. Run: pip install -r requirements.txt")
|
| 68 |
+
sys.exit(1)
|
| 69 |
+
|
| 70 |
+
try:
|
| 71 |
+
import mediapipe
|
| 72 |
+
print("β
MediaPipe")
|
| 73 |
+
except ImportError:
|
| 74 |
+
print("β MediaPipe not installed. Run: pip install -r requirements.txt")
|
| 75 |
+
sys.exit(1)
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
import yt_dlp
|
| 79 |
+
print("β
yt-dlp")
|
| 80 |
+
except ImportError:
|
| 81 |
+
print("β yt-dlp not installed. Run: pip install -r requirements.txt")
|
| 82 |
+
sys.exit(1)
|
| 83 |
+
|
| 84 |
+
print("\nπ All dependencies are available!")
|
| 85 |
+
|
| 86 |
+
print("\nπ Deployment Checklist:")
|
| 87 |
+
print("1. β
app.py - Main Gradio application")
|
| 88 |
+
print("2. β
requirements.txt - Python dependencies")
|
| 89 |
+
print("3. β
README.md - With HF Spaces header")
|
| 90 |
+
print("4. β
Dependencies tested")
|
| 91 |
+
|
| 92 |
+
print("\nπ Ready for Hugging Face Spaces deployment!")
|
| 93 |
+
print("\nπ Deployment Instructions:")
|
| 94 |
+
print("1. Go to https://huggingface.co/spaces")
|
| 95 |
+
print("2. Click 'Create new Space'")
|
| 96 |
+
print("3. Choose 'Gradio' as the SDK")
|
| 97 |
+
print("4. Upload these files:")
|
| 98 |
+
print(" - app.py")
|
| 99 |
+
print(" - requirements.txt")
|
| 100 |
+
print(" - README.md")
|
| 101 |
+
print("5. Wait for automatic deployment")
|
| 102 |
+
print("\nπ Your Space will be available at:")
|
| 103 |
+
print(" https://huggingface.co/spaces/YOUR_USERNAME/athletic-ability-analysis")
|
| 104 |
+
|
| 105 |
+
# Offer to test locally
|
| 106 |
+
test_local = input("\nπ§ͺ Would you like to test the app locally first? (y/n): ")
|
| 107 |
+
if test_local.lower() in ['y', 'yes']:
|
| 108 |
+
print("\nπ Starting local Gradio server...")
|
| 109 |
+
print("π Note: This will open in your browser. Press Ctrl+C to stop.")
|
| 110 |
+
try:
|
| 111 |
+
from app import create_interface
|
| 112 |
+
app = create_interface()
|
| 113 |
+
app.launch(debug=True, share=False)
|
| 114 |
+
except KeyboardInterrupt:
|
| 115 |
+
print("\nβ
Local testing stopped.")
|
| 116 |
+
except Exception as e:
|
| 117 |
+
print(f"\nβ Error running local test: {e}")
|
| 118 |
+
|
| 119 |
+
print("\nπ Thank you for using Athletic Ability Analysis!")
|
| 120 |
+
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.7.1
|
| 2 |
+
opencv-python-headless==4.8.1.78
|
| 3 |
+
numpy==1.24.3
|
| 4 |
+
mediapipe==0.10.3
|
| 5 |
+
yt-dlp==2023.7.6
|
| 6 |
+
pandas==2.0.3
|