pravaah / DEPLOYMENT_GUIDE.md
Prathamesh Sutar
Deployment 2
f4d6026

πŸš€ Pravaah Deployment Guide

This guide will help you deploy the Pravaah Ocean Hazard Detection System with both FastAPI and Gradio interfaces.

πŸ“ Files in Pravaah Folder

Core Application Files:

  • app.py - Gradio web interface (Port 7860)
  • api.py - FastAPI REST API (Port 8000)
  • Dockerfile - Docker configuration for both services
  • requirements.txt - Python dependencies

AI/ML Modules:

  • classifier.py - Hazard classification
  • scraper.py - Twitter data fetching
  • ner.py - Named Entity Recognition
  • sentiment.py - Sentiment analysis
  • translate.py - Translation pipeline
  • pg_db.py - Database operations

Documentation:

  • README.md - Project documentation
  • DEPLOYMENT_GUIDE.md - This file

🌐 Services Overview

FastAPI (Port 8000)

  • REST API for programmatic access
  • Swagger UI at /docs
  • ReDoc at /redoc
  • Health checks at /health

Gradio (Port 7860)

  • Web interface for interactive use
  • Real-time analysis with visual results
  • JSON export functionality

πŸš€ Deployment Steps

1. Deploy to Hugging Face Spaces

  1. Create a new Space:

  2. Upload files:

    • Copy all files from the pravaah folder
    • Upload to your Space repository
  3. Set environment variables:

    • TWITTER_API_KEY - Your Twitter API key
    • SUPABASE_URL - Your Supabase connection string
  4. Deploy:

    • Push to repository
    • Monitor build logs

2. Local Development

# Install dependencies
pip install -r requirements.txt

# Run FastAPI
uvicorn api:app --host 0.0.0.0 --port 8000

# Run Gradio (in another terminal)
python app.py

3. Docker Deployment

# Build image
docker build -t pravaah-ocean-hazard .

# Run container
docker run -p 8000:8000 -p 7860:7860 \
  -e TWITTER_API_KEY=your_key \
  -e SUPABASE_URL=your_url \
  pravaah-ocean-hazard

πŸ“Š API Endpoints

Analysis

  • POST /analyze - Analyze tweets for hazards
  • GET /hazardous-tweets - Get stored hazardous tweets
  • GET /stats - Get analysis statistics

Health & Monitoring

  • GET /health - Health check
  • GET / - Root endpoint

πŸ”§ Configuration

Environment Variables

# Required
TWITTER_API_KEY=your_twitter_api_key
SUPABASE_URL=postgresql://postgres:[password]@db.[project-ref].supabase.co:5432/postgres

# Optional
SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key

Ports

  • 8000 - FastAPI REST API
  • 7860 - Gradio Web Interface

πŸ§ͺ Testing

Test API Endpoints

# Health check
curl http://localhost:8000/health

# Analyze tweets
curl -X POST "http://localhost:8000/analyze" \
  -H "Content-Type: application/json" \
  -d '{"limit": 10}'

# Get statistics
curl http://localhost:8000/stats

Test Web Interface

  • Open http://localhost:7860 in browser
  • Use the interactive interface to analyze tweets

πŸ“ˆ Monitoring

Health Checks

  • FastAPI: http://localhost:8000/health
  • Gradio: Check if port 7860 is accessible

Logs

  • Both services log to stdout
  • Check Docker logs: docker logs <container_id>

🎯 Features

FastAPI Features

  • βœ… RESTful API endpoints
  • βœ… Automatic API documentation
  • βœ… Request/response validation
  • βœ… Error handling
  • βœ… CORS support
  • βœ… Database integration

Gradio Features

  • βœ… Interactive web interface
  • βœ… Real-time analysis
  • βœ… Visual results display
  • βœ… JSON export
  • βœ… User-friendly controls

πŸ”„ Updates

To update your deployment:

  1. Make changes to your code
  2. Commit and push to repository
  3. Hugging Face Spaces will automatically rebuild
  4. Both services will restart with new code

πŸ†˜ Troubleshooting

Common Issues

  1. Port conflicts - Ensure ports 8000 and 7860 are available
  2. Database connection - Check Supabase credentials
  3. API key issues - Verify Twitter API key is valid
  4. Model loading - Check internet connection for model downloads

Getting Help

  • Check logs for error messages
  • Verify environment variables
  • Test individual components
  • Check Hugging Face Spaces documentation

πŸŽ‰ Success!

Once deployed, you'll have:

  • FastAPI at https://your-space.hf.space:8000
  • Gradio at https://your-space.hf.space:7860
  • API docs at https://your-space.hf.space:8000/docs

Your Ocean Hazard Detection System is now live with both API and web interfaces! 🌊