Spaces:
Sleeping
Sleeping
Fix deployment: add startup script, env config, routing fixes, and reorganize classifier service
0cc2bd2 | # 🦠 BacSense v2 - Hugging Face Deployment Guide | |
| ## Current Status | |
| - **Frontend**: Deployed on Vercel ✅ | |
| - **Backend**: Deployed on Hugging Face Spaces (Docker) ⚠️ | |
| ## Issue Diagnosis | |
| The "Not Found" error on Hugging Face typically means: | |
| 1. The server isn't starting properly | |
| 2. The port configuration is incorrect | |
| 3. Model files aren't being found during initialization | |
| ## Solution Implemented | |
| ### 1. Updated Dockerfile | |
| - Added better debugging with startup script | |
| - Configured proper environment variables for Hugging Face | |
| - Added curl for health checks | |
| ### 2. Added Startup Script (`start.sh`) | |
| - Shows directory contents on startup | |
| - Verifies model files are present | |
| - Starts uvicorn server with proper configuration | |
| ### 3. API Configuration | |
| - Root endpoint (`/`) now shows a welcome page | |
| - Health check available at `/health` | |
| - Debug endpoint at `/debug_model` to diagnose issues | |
| - API documentation at `/docs` | |
| ## How to Deploy | |
| ### Step 1: Push to Hugging Face | |
| ```bash | |
| cd "e:\1-Antigravity Python\Bacsense 2.0\BacSense-API" | |
| git add . | |
| git commit -m "Fix deployment: add startup script and debugging" | |
| git push origin main | |
| ``` | |
| ### Step 2: Check Deployment Logs | |
| 1. Go to your Hugging Face Space: https://huggingface.co/spaces/joytheslothh/BacSense-API | |
| 2. Click on "Logs" tab | |
| 3. Watch the startup logs to see if: | |
| - All dependencies install successfully | |
| - Model files are found | |
| - Server starts on port 7860 | |
| ### Step 3: Test Endpoints | |
| Once deployed, test these endpoints: | |
| **Health Check:** | |
| ``` | |
| https://joytheslothh-bacsense-api.hf.space/health | |
| ``` | |
| **API Documentation:** | |
| ``` | |
| https://joytheslothh-bacsense-api.hf.space/docs | |
| ``` | |
| **Debug Model:** | |
| ``` | |
| https://joytheslothh-bacsense-api.hf.space/debug_model | |
| ``` | |
| ## Frontend Configuration (Vercel) | |
| Update your frontend API URL in Vercel to point to: | |
| ``` | |
| https://joytheslothh-bacsense-api.hf.space | |
| ``` | |
| Or in your frontend code, update the API base URL: | |
| ```typescript | |
| // In your React code | |
| const API_URL = "https://joytheslothh-bacsense-api.hf.space"; | |
| ``` | |
| ## Troubleshooting | |
| ### If you still see "Not Found": | |
| 1. **Check the logs** - Look for import errors or missing files | |
| 2. **Verify model loading** - Visit `/debug_model` endpoint | |
| 3. **Test locally** - Run `docker build -t bacsense .` and `docker run -p 7860:7860 bacsense` | |
| ### Common Issues: | |
| **TensorFlow Import Error:** | |
| - Ensure all requirements are installed | |
| - Check if TensorFlow CPU version is compatible | |
| **Model Files Not Found:** | |
| - Verify `bacsense_v2_package` folder exists in the repo | |
| - Check that `.keras` and `.pkl` files are tracked by Git LFS | |
| **Port Binding Issue:** | |
| - Hugging Face expects port 7860 | |
| - Server must bind to `0.0.0.0` not `localhost` | |
| ## Alternative: Streamlit-Only Deployment | |
| If FastAPI continues to have issues, you can deploy as a pure Streamlit app: | |
| 1. Rename `app.py` to `streamlit_app.py` | |
| 2. Update Dockerfile CMD to: `CMD ["streamlit", "run", "streamlit_app.py"]` | |
| This gives you the dashboard without the separate API backend. | |