DetectMeBotBackend / QUICKSTART.md
Gradii's picture
setup
4fc93b8
|
Raw
History Blame
3.65 kB
# 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.