Spaces:
Sleeping
Sleeping
π 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 servicesrequirements.txt- Python dependencies
AI/ML Modules:
classifier.py- Hazard classificationscraper.py- Twitter data fetchingner.py- Named Entity Recognitionsentiment.py- Sentiment analysistranslate.py- Translation pipelinepg_db.py- Database operations
Documentation:
README.md- Project documentationDEPLOYMENT_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
Create a new Space:
- Go to huggingface.co/spaces
- Choose Docker SDK
- Name:
pravaah-ocean-hazard-detection
Upload files:
- Copy all files from the
pravaahfolder - Upload to your Space repository
- Copy all files from the
Set environment variables:
TWITTER_API_KEY- Your Twitter API keySUPABASE_URL- Your Supabase connection string
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:7860in 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:
- Make changes to your code
- Commit and push to repository
- Hugging Face Spaces will automatically rebuild
- Both services will restart with new code
π Troubleshooting
Common Issues
- Port conflicts - Ensure ports 8000 and 7860 are available
- Database connection - Check Supabase credentials
- API key issues - Verify Twitter API key is valid
- 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! π