Spaces:
Runtime error
Runtime error
| # Quick Reference Guide | |
| ## π Starting the Backend | |
| ### First Time Setup (Windows) | |
| ```powershell | |
| cd backend | |
| python setup.py | |
| venv\Scripts\activate | |
| python main.py | |
| ``` | |
| ### First Time Setup (macOS/Linux) | |
| ```bash | |
| cd backend | |
| python setup.py | |
| source venv/bin/activate | |
| python main.py | |
| ``` | |
| ### Subsequent Times | |
| ```bash | |
| cd backend | |
| run.bat # Windows | |
| # OR | |
| ./run.sh # macOS/Linux | |
| ``` | |
| ## π‘ API Quick Test | |
| ### Health Check | |
| ```bash | |
| curl http://localhost:8000/ | |
| ``` | |
| ### Analyze a File | |
| ```bash | |
| curl -X POST http://localhost:8000/analyze \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"file_url": "https://example.com/video.mp4"}' | |
| ``` | |
| ### Documentation | |
| - **Swagger UI**: http://localhost:8000/docs | |
| - **ReDoc**: http://localhost:8000/redoc | |
| ## π§ Configuration | |
| Edit `backend/.env`: | |
| ```env | |
| HOST=127.0.0.1 | |
| PORT=8000 | |
| DEFAULT_DETECTOR_MODEL=mock | |
| LOG_LEVEL=INFO | |
| DOWNLOAD_TIMEOUT=30 | |
| MAX_FILE_SIZE=104857600 | |
| ``` | |
| ## π¦ Project Structure | |
| ``` | |
| backend/ | |
| βββ app/ | |
| β βββ api/ # Routes | |
| β βββ services/ # Business logic (download, ML models, queuing) | |
| β βββ models/ # Data schemas | |
| β βββ core/ # Configuration | |
| β βββ utils/ # Exceptions | |
| βββ main.py # Entry point | |
| βββ README.md # Full API docs | |
| βββ DEVELOPMENT.md # Adding models, Redis, etc. | |
| ``` | |
| ## β Adding a New ML Model | |
| 1. Copy `DETECTOR_TEMPLATE.py` | |
| 2. Implement the `detect()` method | |
| 3. Register in `app/services/detector/__init__.py` | |
| 4. Update `.env` if setting as default | |
| See `DEVELOPMENT.md` for detailed steps. | |
| ## π Integrating with Discord Bot | |
| Use `DISCORD_BOT_EXAMPLE.py` as a template: | |
| ```python | |
| from discord_bot_example import setup | |
| # In your bot startup: | |
| await setup(bot) | |
| # Then use in your bot: | |
| # !deepfake_check https://example.com/video.mp4 | |
| # !backend_status | |
| ``` | |
| ## π Common Issues | |
| | Problem | Solution | | |
| |---------|----------| | |
| | `ModuleNotFoundError` | Activate venv first | | |
| | Port 8000 in use | Change port: `PORT=8001 python main.py` | | |
| | Import errors | `pip install -r requirements.txt` | | |
| | Download timeout | Increase: `DOWNLOAD_TIMEOUT=60 python main.py` | | |
| ## π Supported File Types | |
| Any file type via URL: | |
| - Videos: `.mp4`, `.webm`, `.avi`, etc. | |
| - Images: `.jpg`, `.png`, `.gif`, etc. | |
| - Any file up to 100 MB (configurable) | |
| ## π Async Support | |
| Backend is fully async: | |
| - Non-blocking file downloads | |
| - Concurrent requests supported | |
| - Scalable to Redis task queuing | |
| ## π Logging Levels | |
| ```bash | |
| # Normal operation | |
| LOG_LEVEL=INFO python main.py | |
| # Verbose debugging | |
| LOG_LEVEL=DEBUG python main.py | |
| # Warnings and errors only | |
| LOG_LEVEL=WARNING python main.py | |
| ``` | |
| ## π Production Deployment | |
| For production, use Gunicorn with Uvicorn: | |
| ```bash | |
| pip install gunicorn | |
| gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000 | |
| ``` | |
| ## π Response Format | |
| **Success:** | |
| ```json | |
| { | |
| "is_deepfake": true, | |
| "confidence": 0.95, | |
| "analysis_time": 1.5, | |
| "model_used": "mock" | |
| } | |
| ``` | |
| **Error:** | |
| ```json | |
| { | |
| "error": "Invalid URL format", | |
| "status_code": 400, | |
| "details": null | |
| } | |
| ``` | |
| ## π Default Security Settings | |
| - Max file size: 100 MB | |
| - Download timeout: 30 seconds | |
| - URL validation: Enabled | |
| - Error details: Minimal (no leakage) | |
| Increase security for production: | |
| - Add API keys/authentication | |
| - Implement rate limiting | |
| - Use HTTPS | |
| - Add CORS restrictions | |
| ## π― Next Steps | |
| 1. β Backend running? | |
| 2. β³ Test with sample URLs | |
| 3. β³ Create Discord bot using example | |
| 4. β³ Add your ML models | |
| 5. β³ Deploy to production | |
| --- | |
| For complete documentation, see `README.md` and `DEVELOPMENT.md` in the backend folder. | |