Spaces:
Runtime error
Runtime error
# π 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! π |