safetyMaster / gradio-deploy.md
mrvero's picture
Upload folder using huggingface_hub
0469d65 verified

A newer version of the Gradio SDK is available: 5.43.1

Upgrade

πŸš€ 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 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:
    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
  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:

# 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

#!/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)

---
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:

# 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! πŸš€