Spaces:
Paused
Paused
File size: 7,446 Bytes
a26cc05 f3b5cd6 a26cc05 959d1ac a26cc05 959d1ac a422282 959d1ac e62f2f6 959d1ac e62f2f6 959d1ac a422282 959d1ac a422282 959d1ac a422282 959d1ac a422282 959d1ac a422282 959d1ac e62f2f6 959d1ac e62f2f6 959d1ac e62f2f6 959d1ac |
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 |
---
title: Par-ity Project
emoji: ⛳
colorFrom: blue
colorTo: green
sdk: streamlit
app_file: app/streamlit_app.py
pinned: false
---
# Par-ity Project: Golf Swing Analysis with AI Assistant ⛳🏌️♀️
A comprehensive golf swing analysis platform that combines computer vision-based swing analysis with an AI-powered technique assistant. This integrated system provides both automated video analysis and expert knowledge retrieval for improving your golf swing.
## Features
### 🎥 Video Analysis
- Upload or provide YouTube links to golf swing videos
- Automated swing analysis using computer vision
- Pose estimation and tracking
- Swing phase segmentation (setup, backswing, downswing, follow-through)
- Club and ball trajectory analysis
- Annotated video generation with visual feedback
- Key position comparison (setup, top of backswing, impact)
- AI-powered improvement recommendations
### 🤖 Golf Swing Technique Assistant (RAG)
- **Expert Knowledge Base**: 2,000+ professional golf instruction articles
- **Semantic Search**: Ask questions in natural language
- **Contextual Answers**: Get detailed responses with source citations
- **Interactive Chat**: Build conversations about your swing technique
- **TPI Content**: Based on Titleist Performance Institute materials
## What You Can Do
### Video Analysis Options
After uploading a video, you get 4 analysis options:
1. **Generate Annotated Video** - Visual feedback showing swing phases and metrics
2. **Generate Improvement Recommendations** - AI-powered personalized tips
3. **Key Frame Analysis** - Detailed review of critical swing positions
4. **Golf Swing Chatbot** - Ask specific technique questions
### Example Questions for the AI Assistant
- "What wrist motion happens during the downswing?"
- "I'm having trouble with my slice, can you help?"
- "What should I focus on to increase my driving distance?"
- "How do I fix my inconsistent ball striking?"
- "What physical limitations can affect my swing?"
## Setup Instructions
### 1. Install Dependencies
```bash
pip install -r requirements.txt
```
### 2. Directory Setup
```bash
./setup_directories.sh
```
### 3. OpenAI API Key (Optional)
For enhanced AI responses, set up an OpenAI API key:
**Option 1: Environment File**
```bash
cp .env.example .env
# Edit .env and add your API key
```
**Option 2: Streamlit Secrets**
Create `.streamlit/secrets.toml`:
```toml
[openai]
api_key = "your-openai-api-key-here"
```
**Option 3: Enter in App**
You can also enter the API key directly in the Streamlit interface.
### 4. Run the Application
```bash
cd app
streamlit run streamlit_app.py
```
Or use the convenience script:
```bash
./run_streamlit.sh
```
## How It Works
### Video Analysis Pipeline
1. **Video Processing**: Extracts frames and detects objects using YOLOv8
2. **Pose Analysis**: Uses MediaPipe for detailed body positioning
3. **Swing Segmentation**: Identifies swing phases automatically
4. **Trajectory Analysis**: Tracks club and ball movement
5. **AI Recommendations**: Generates personalized improvement tips
### RAG (Retrieval-Augmented Generation) System
1. **Knowledge Processing**: Loads and processes 2,000+ golf instruction articles
2. **Semantic Embeddings**: Creates vector representations using Sentence Transformers
3. **Smart Search**: Uses FAISS for fast similarity search
4. **Response Generation**: Combines retrieved knowledge with AI (GPT-3.5) or fallback mode
## File Structure
```
Golf_Swing_Analysis/
├── app/ # Main application
│ ├── streamlit_app.py # Integrated Streamlit app
│ ├── golf_swing_rag.py # RAG system
│ ├── models/ # Analysis models
│ ├── utils/ # Utility functions
│ └── components/ # UI components
├── golf_swing_articles_complete.csv # Knowledge base (2,000+ articles)
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── test_rag_integration.py # Integration test script
└── Generated files (after first run):
├── golf_swing_embeddings.pkl # Cached embeddings
├── golf_swing_index.faiss # Vector search index
└── downloads/ # Processed videos
```
## Technical Details
### Technologies Used
- **Computer Vision**: YOLOv8, MediaPipe, OpenCV
- **AI/ML**: OpenAI GPT-3.5/4, Ollama (local LLM option)
- **RAG Stack**: Sentence Transformers, FAISS, LangChain
- **Web Interface**: Streamlit
- **Data Processing**: Pandas, NumPy
### Performance Features
- **Cached Embeddings**: First-time setup creates embeddings saved for future use
- **Efficient Search**: FAISS enables fast similarity search over thousands of chunks
- **Automatic Cleanup**: Temporary files are managed automatically
- **Batch Processing**: Video frames and embeddings processed efficiently
## Usage Guide
### 1. Video Analysis Workflow
1. Choose input method (YouTube URL or file upload)
2. Click "Analyze Swing" to process the video
3. Select from 4 analysis options
4. Download results and annotated videos
### 2. AI Assistant Workflow
1. Click "Golf Swing Chatbot" after video analysis (or use standalone)
2. Ask questions about golf swing technique
3. Review detailed answers with source citations
4. Build conversations for comprehensive understanding
## Example Use Cases
### Video Analysis
- **Beginner Golfer**: Upload practice swing video → Get annotated feedback → Learn proper positions
- **Intermediate Player**: Analyze driver swing → Get AI recommendations → Focus on specific improvements
- **Coach**: Use key frame analysis → Show students critical positions → Provide visual evidence
### AI Assistant
- **Technique Questions**: "How should my weight shift during the swing?"
- **Problem Solving**: "I keep hitting fat shots with my irons, what's wrong?"
- **Learning**: "Explain the biomechanics of the golf swing"
- **Specific Issues**: "I have limited hip mobility, how does this affect my swing?"
## Troubleshooting
### First Run Setup
- Initial embedding creation takes 5-10 minutes (one-time process)
- Ensure adequate RAM (8GB+ recommended) for large knowledge base
- Video processing time depends on length and resolution
### Common Issues
- **Missing Dependencies**: Run `pip install --upgrade -r requirements.txt`
- **Import Errors**: Ensure you're running from the correct directory
- **RAG Not Available**: Check that `golf_swing_articles_complete.csv` exists
- **Video Issues**: Ensure videos are in supported formats (MP4, MOV, AVI)
### Testing Integration
Run the test script to verify everything works:
```bash
python3 test_rag_integration.py
```
## Contributing
This system is designed to be extensible:
1. **Video Analysis**: Add new computer vision models or metrics
2. **Knowledge Base**: Include additional golf instruction sources
3. **AI Models**: Experiment with different embedding models or LLMs
4. **UI/UX**: Enhance the Streamlit interface with new features
## License
This project is for educational and personal use. The golf instruction content is sourced from publicly available articles and should be attributed to original sources.
---
**Built with ❤️ to empower golfers with AI-powered analysis and expert knowledge** |