Spaces:
Running
Running
| # π 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:** | |
| - Go to [huggingface.co/spaces](https://huggingface.co/spaces) | |
| - Choose **Docker** SDK | |
| - Name: `pravaah-ocean-hazard-detection` | |
| 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** | |
| ```bash | |
| # 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** | |
| ```bash | |
| # 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** | |
| ```bash | |
| # 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** | |
| ```bash | |
| # 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! π | |