Spaces:
Runtime error
Runtime error
File size: 6,067 Bytes
0469d65 |
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 231 232 233 234 235 236 237 |
# π Deploy SafetyMaster Pro - Gradio Version
## π― Why Gradio?
Gradio is **perfect** for AI applications like SafetyMaster Pro because:
- β
**Super easy deployment** - One file, multiple hosting options
- β
**Built for AI/ML** - Perfect for computer vision apps
- β
**Free hosting options** - Hugging Face Spaces, Gradio Cloud
- β
**Beautiful UI** - Professional interface out of the box
- β
**No complex setup** - No Docker, no server configuration
## π What You Get
Your Gradio app includes:
- π· **Image Upload Analysis** - Drag & drop safety detection
- πΉ **Live Camera Monitoring** - Real-time PPE detection
- π **Violation Logging** - Track safety compliance
- π€ **AI Model Info** - Model details and capabilities
## π Free Hosting Options
### 1. π€ Hugging Face Spaces (Recommended)
**Best for**: Public demos, sharing with others
**Cost**: 100% Free
**Setup Time**: 5 minutes
#### Steps:
1. **Create Account**: Go to [huggingface.co](https://huggingface.co) and sign up
2. **Create Space**:
- Click "Create new Space"
- Name: `safetymaster-pro`
- SDK: `Gradio`
- Hardware: `CPU basic` (free)
3. **Upload Files**:
```
gradio_interface.py
safety_detector.py
camera_manager.py
config.py
requirements.txt
```
4. **Create app.py**:
```python
from gradio_interface import main
if __name__ == "__main__":
main()
```
5. **Deploy**: Files auto-deploy when uploaded!
**Your app will be live at**: `https://huggingface.co/spaces/yourusername/safetymaster-pro`
### 2. βοΈ Gradio Cloud
**Best for**: Private apps, team use
**Cost**: Free tier available
**Setup Time**: 2 minutes
#### Steps:
1. **Sign up**: [gradio.app](https://gradio.app)
2. **Upload**: Drag `gradio_interface.py` to the interface
3. **Deploy**: Click "Deploy" - that's it!
### 3. π Render (Docker-free)
**Best for**: Custom domains, production use
**Cost**: Free tier available
#### Steps:
1. **Push to GitHub**: Your Gradio files
2. **Connect Render**: Link your repository
3. **Deploy**: Render auto-detects Gradio apps
### 4. π Streamlit Cloud (Alternative)
Convert to Streamlit if preferred - similar to Gradio
## π§ Local Testing
Test your Gradio app locally first:
```bash
# Install dependencies
pip install -r requirements.txt
# Run the app
python gradio_interface.py
```
Visit: `http://localhost:7860`
## π File Structure for Deployment
```
safetymaster-gradio/
βββ gradio_interface.py # Main Gradio app
βββ safety_detector.py # AI detection logic
βββ camera_manager.py # Camera handling
βββ config.py # Configuration
βββ requirements.txt # Dependencies
βββ app.py # Entry point (for HF Spaces)
βββ README.md # Documentation
```
## π¨ Gradio Features
### π· Image Analysis Tab
- **Drag & drop** image upload
- **Instant detection** with bounding boxes
- **Detailed results** in JSON format
- **Human-readable summary**
### πΉ Live Camera Tab
- **Start/Stop** camera monitoring
- **Real-time detection** display
- **Live status** updates
- **Violation alerts**
### π Violation Log Tab
- **Recent violations** history
- **Auto-refresh** every 10 seconds
- **Detailed timestamps**
- **Severity indicators**
### π€ Model Info Tab
- **AI model details**
- **Supported equipment types**
- **Detection capabilities**
## π Quick Deploy to Hugging Face Spaces
Create these files for instant deployment:
### app.py
```python
#!/usr/bin/env python3
"""
SafetyMaster Pro - Hugging Face Spaces Entry Point
"""
from gradio_interface import main
if __name__ == "__main__":
main()
```
### README.md (for HF Spaces)
```markdown
---
title: SafetyMaster Pro
emoji: π‘οΈ
colorFrom: blue
colorTo: red
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
pinned: false
---
# SafetyMaster Pro - AI Safety Monitoring
Real-time PPE detection and safety compliance monitoring using YOLOv8.
## Features
- Hard Hat Detection
- Safety Vest Detection
- Face Mask Detection
- Real-time Camera Monitoring
- Violation Logging
Upload an image or use your camera to detect safety equipment!
```
## π§ Environment Variables
For production deployment, set these:
```bash
# Optional - for custom configurations
GRADIO_SERVER_NAME=0.0.0.0
GRADIO_SERVER_PORT=7860
GRADIO_SHARE=False
```
## π Performance Optimization
### For Free Hosting:
- β
Models download automatically (already configured)
- β
Efficient memory usage
- β
Optimized for CPU inference
- β
Gradio handles caching
### Memory Usage:
- **Base app**: ~200MB
- **With AI model**: ~800MB
- **Total**: Under 1GB (fits free tiers)
## π― Deployment Comparison
| Platform | Cost | Setup Time | Features |
|----------|------|------------|----------|
| **Hugging Face Spaces** | Free | 5 min | Public, easy sharing |
| **Gradio Cloud** | Free tier | 2 min | Private, team access |
| **Render** | Free tier | 10 min | Custom domain |
| **Local** | Free | 1 min | Full control |
## π Troubleshooting
### Common Issues:
1. **Model download fails**
- Solution: Models auto-download on first run (may take 2-3 minutes)
2. **Camera not working**
- Solution: Browser security - allow camera access
3. **Out of memory**
- Solution: Use CPU inference (already configured)
4. **Slow startup**
- Solution: Normal for first run, subsequent loads are fast
## π Success!
Once deployed, your SafetyMaster Pro Gradio app will have:
- β
**Professional UI** - Clean, modern interface
- β
**Real-time detection** - Live camera monitoring
- β
**Easy sharing** - Send link to anyone
- β
**Mobile friendly** - Works on phones/tablets
- β
**No installation** - Users just visit the URL
## π Next Steps
1. **Test locally**: `python gradio_interface.py`
2. **Choose platform**: Hugging Face Spaces recommended
3. **Deploy**: Upload files and go live!
4. **Share**: Send the URL to your team
---
**Ready to deploy?** Start with Hugging Face Spaces for the easiest experience! π |