Spaces:
Running
Running
startuping cleanup
Browse files- QUICKSTART.md +6 -144
- TODO.md +2 -0
- backend/.env.example +1 -0
- backend/README.md +0 -199
- backend/app/__init__.py +7 -30
- backend/app/api/routes.py +1 -0
- backend/main.py +3 -33
- backend/run.bat +0 -6
- backend/setup.py +0 -13
QUICKSTART.md
CHANGED
|
@@ -16,14 +16,17 @@ cd backend
|
|
| 16 |
python setup.py
|
| 17 |
source venv/bin/activate
|
| 18 |
python main.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
```
|
| 20 |
|
| 21 |
### Subsequent Times
|
| 22 |
```bash
|
| 23 |
cd backend
|
| 24 |
-
run.bat
|
| 25 |
-
# OR
|
| 26 |
-
./run.sh # macOS/Linux
|
| 27 |
```
|
| 28 |
|
| 29 |
## π‘ API Quick Test
|
|
@@ -44,144 +47,3 @@ curl -X POST http://localhost:8000/analyze \
|
|
| 44 |
- **Swagger UI**: http://localhost:8000/docs
|
| 45 |
- **ReDoc**: http://localhost:8000/redoc
|
| 46 |
|
| 47 |
-
## π§ Configuration
|
| 48 |
-
|
| 49 |
-
Edit `backend/.env`:
|
| 50 |
-
```env
|
| 51 |
-
HOST=127.0.0.1
|
| 52 |
-
PORT=8000
|
| 53 |
-
DEFAULT_DETECTOR_MODEL=mock
|
| 54 |
-
LOG_LEVEL=INFO
|
| 55 |
-
DOWNLOAD_TIMEOUT=30
|
| 56 |
-
MAX_FILE_SIZE=104857600
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
## π¦ Project Structure
|
| 60 |
-
|
| 61 |
-
```
|
| 62 |
-
backend/
|
| 63 |
-
βββ app/
|
| 64 |
-
β βββ api/ # Routes
|
| 65 |
-
β βββ services/ # Business logic (download, ML models, queuing)
|
| 66 |
-
β βββ models/ # Data schemas
|
| 67 |
-
β βββ core/ # Configuration
|
| 68 |
-
β βββ utils/ # Exceptions
|
| 69 |
-
βββ main.py # Entry point
|
| 70 |
-
βββ README.md # Full API docs
|
| 71 |
-
βββ DEVELOPMENT.md # Adding models, Redis, etc.
|
| 72 |
-
```
|
| 73 |
-
|
| 74 |
-
## β Adding a New ML Model
|
| 75 |
-
|
| 76 |
-
1. Copy `DETECTOR_TEMPLATE.py`
|
| 77 |
-
2. Implement the `detect()` method
|
| 78 |
-
3. Register in `app/services/detector/__init__.py`
|
| 79 |
-
4. Update `.env` if setting as default
|
| 80 |
-
|
| 81 |
-
See `DEVELOPMENT.md` for detailed steps.
|
| 82 |
-
|
| 83 |
-
## π Integrating with Discord Bot
|
| 84 |
-
|
| 85 |
-
Use `DISCORD_BOT_EXAMPLE.py` as a template:
|
| 86 |
-
|
| 87 |
-
```python
|
| 88 |
-
from discord_bot_example import setup
|
| 89 |
-
|
| 90 |
-
# In your bot startup:
|
| 91 |
-
await setup(bot)
|
| 92 |
-
|
| 93 |
-
# Then use in your bot:
|
| 94 |
-
# !deepfake_check https://example.com/video.mp4
|
| 95 |
-
# !backend_status
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
## π Common Issues
|
| 99 |
-
|
| 100 |
-
| Problem | Solution |
|
| 101 |
-
|---------|----------|
|
| 102 |
-
| `ModuleNotFoundError` | Activate venv first |
|
| 103 |
-
| Port 8000 in use | Change port: `PORT=8001 python main.py` |
|
| 104 |
-
| Import errors | `pip install -r requirements.txt` |
|
| 105 |
-
| Download timeout | Increase: `DOWNLOAD_TIMEOUT=60 python main.py` |
|
| 106 |
-
|
| 107 |
-
## π Supported File Types
|
| 108 |
-
|
| 109 |
-
Any file type via URL:
|
| 110 |
-
- Videos: `.mp4`, `.webm`, `.avi`, etc.
|
| 111 |
-
- Images: `.jpg`, `.png`, `.gif`, etc.
|
| 112 |
-
- Any file up to 100 MB (configurable)
|
| 113 |
-
|
| 114 |
-
## π Async Support
|
| 115 |
-
|
| 116 |
-
Backend is fully async:
|
| 117 |
-
- Non-blocking file downloads
|
| 118 |
-
- Concurrent requests supported
|
| 119 |
-
- Scalable to Redis task queuing
|
| 120 |
-
|
| 121 |
-
## π Logging Levels
|
| 122 |
-
|
| 123 |
-
```bash
|
| 124 |
-
# Normal operation
|
| 125 |
-
LOG_LEVEL=INFO python main.py
|
| 126 |
-
|
| 127 |
-
# Verbose debugging
|
| 128 |
-
LOG_LEVEL=DEBUG python main.py
|
| 129 |
-
|
| 130 |
-
# Warnings and errors only
|
| 131 |
-
LOG_LEVEL=WARNING python main.py
|
| 132 |
-
```
|
| 133 |
-
|
| 134 |
-
## π Production Deployment
|
| 135 |
-
|
| 136 |
-
For production, use Gunicorn with Uvicorn:
|
| 137 |
-
|
| 138 |
-
```bash
|
| 139 |
-
pip install gunicorn
|
| 140 |
-
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
|
| 141 |
-
```
|
| 142 |
-
|
| 143 |
-
## π Response Format
|
| 144 |
-
|
| 145 |
-
**Success:**
|
| 146 |
-
```json
|
| 147 |
-
{
|
| 148 |
-
"is_deepfake": true,
|
| 149 |
-
"confidence": 0.95,
|
| 150 |
-
"analysis_time": 1.5,
|
| 151 |
-
"model_used": "mock"
|
| 152 |
-
}
|
| 153 |
-
```
|
| 154 |
-
|
| 155 |
-
**Error:**
|
| 156 |
-
```json
|
| 157 |
-
{
|
| 158 |
-
"error": "Invalid URL format",
|
| 159 |
-
"status_code": 400,
|
| 160 |
-
"details": null
|
| 161 |
-
}
|
| 162 |
-
```
|
| 163 |
-
|
| 164 |
-
## π Default Security Settings
|
| 165 |
-
|
| 166 |
-
- Max file size: 100 MB
|
| 167 |
-
- Download timeout: 30 seconds
|
| 168 |
-
- URL validation: Enabled
|
| 169 |
-
- Error details: Minimal (no leakage)
|
| 170 |
-
|
| 171 |
-
Increase security for production:
|
| 172 |
-
- Add API keys/authentication
|
| 173 |
-
- Implement rate limiting
|
| 174 |
-
- Use HTTPS
|
| 175 |
-
- Add CORS restrictions
|
| 176 |
-
|
| 177 |
-
## π― Next Steps
|
| 178 |
-
|
| 179 |
-
1. β
Backend running?
|
| 180 |
-
2. β³ Test with sample URLs
|
| 181 |
-
3. β³ Create Discord bot using example
|
| 182 |
-
4. β³ Add your ML models
|
| 183 |
-
5. β³ Deploy to production
|
| 184 |
-
|
| 185 |
-
---
|
| 186 |
-
|
| 187 |
-
For complete documentation, see `README.md` and `DEVELOPMENT.md` in the backend folder.
|
|
|
|
| 16 |
python setup.py
|
| 17 |
source venv/bin/activate
|
| 18 |
python main.py
|
| 19 |
+
|
| 20 |
+
or
|
| 21 |
+
|
| 22 |
+
"uvicorn app:app --reload --host 127.0.0.1 --port 8000"
|
| 23 |
+
"uvicorn app:app --host 127.0.0.1 --port 8000"
|
| 24 |
```
|
| 25 |
|
| 26 |
### Subsequent Times
|
| 27 |
```bash
|
| 28 |
cd backend
|
| 29 |
+
run.bat
|
|
|
|
|
|
|
| 30 |
```
|
| 31 |
|
| 32 |
## π‘ API Quick Test
|
|
|
|
| 47 |
- **Swagger UI**: http://localhost:8000/docs
|
| 48 |
- **ReDoc**: http://localhost:8000/redoc
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TODO.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BezpieczeΕstwo (SSRF - Server-Side Request Forgery): TwΓ³j backend pobiera pliki z dowolnego przekazanego adresu URL. ZΕoΕliwy uΕΌytkownik mΓ³gΕby podaΔ URL wskazujΔ
cy na wewnΔtrzne zasoby Twojej sieci (np. http://localhost:8080/admin). Warto zaimplementowaΔ w download_file walidacjΔ, ktΓ³ra pozwala na pobieranie plikΓ³w wyΕΔ
cznie z zaufanych domen (np. tylko z *.discordapp.com i *.media.discordapp.net).
|
| 2 |
+
|
backend/.env.example
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
APP_NAME=Deepfake Detection Service
|
| 5 |
APP_VERSION=1.0.0
|
| 6 |
DEBUG=True
|
|
|
|
| 7 |
|
| 8 |
# Server Configuration
|
| 9 |
HOST=127.0.0.1
|
|
|
|
| 4 |
APP_NAME=Deepfake Detection Service
|
| 5 |
APP_VERSION=1.0.0
|
| 6 |
DEBUG=True
|
| 7 |
+
RELOAD=True
|
| 8 |
|
| 9 |
# Server Configuration
|
| 10 |
HOST=127.0.0.1
|
backend/README.md
CHANGED
|
@@ -1,35 +1,5 @@
|
|
| 1 |
# Deepfake Detection Service Backend
|
| 2 |
|
| 3 |
-
A scalable FastAPI backend for deepfake detection with support for multiple ML models and future Redis integration for task queuing.
|
| 4 |
-
|
| 5 |
-
## π Project Structure
|
| 6 |
-
|
| 7 |
-
```
|
| 8 |
-
backend/
|
| 9 |
-
βββ app/
|
| 10 |
-
β βββ core/ # Core configuration and setup
|
| 11 |
-
β β βββ config.py # Settings management
|
| 12 |
-
β β βββ logging_config.py # Logging setup
|
| 13 |
-
β βββ models/ # Data models
|
| 14 |
-
β β βββ schemas.py # Pydantic request/response models
|
| 15 |
-
β βββ services/ # Business logic layer
|
| 16 |
-
β β βββ download.py # File download service
|
| 17 |
-
β β βββ queue.py # Task queue service (Redis-ready)
|
| 18 |
-
β β βββ detector/ # ML detector models
|
| 19 |
-
β β βββ base.py # Abstract base detector class
|
| 20 |
-
β β βββ mock.py # Mock detector implementation
|
| 21 |
-
β βββ api/ # API endpoints
|
| 22 |
-
β β βββ routes.py # Route handlers
|
| 23 |
-
β βββ utils/ # Utilities
|
| 24 |
-
β βββ exceptions.py # Custom exceptions
|
| 25 |
-
βββ main.py # Application entry point
|
| 26 |
-
βββ requirements.txt # Python dependencies
|
| 27 |
-
βββ .env.example # Example environment variables
|
| 28 |
-
βββ README.md # This file
|
| 29 |
-
```
|
| 30 |
-
|
| 31 |
-
## π Quick Start
|
| 32 |
-
|
| 33 |
### Prerequisites
|
| 34 |
- Python 3.8+
|
| 35 |
- pip or conda
|
|
@@ -120,100 +90,6 @@ Content-Type: application/json
|
|
| 120 |
- `408 Request Timeout`: File download timed out
|
| 121 |
- `500 Internal Server Error`: Server error during analysis
|
| 122 |
|
| 123 |
-
## βοΈ Configuration
|
| 124 |
-
|
| 125 |
-
Configuration is managed through environment variables. Create a `.env` file in the `backend/` directory:
|
| 126 |
-
|
| 127 |
-
```bash
|
| 128 |
-
cp .env.example .env
|
| 129 |
-
```
|
| 130 |
-
|
| 131 |
-
Edit `.env` with your settings:
|
| 132 |
-
|
| 133 |
-
```env
|
| 134 |
-
# Server
|
| 135 |
-
HOST=127.0.0.1
|
| 136 |
-
PORT=8000
|
| 137 |
-
|
| 138 |
-
# File handling
|
| 139 |
-
DOWNLOAD_TIMEOUT=30
|
| 140 |
-
MAX_FILE_SIZE=104857600 # 100 MB
|
| 141 |
-
|
| 142 |
-
# ML Model
|
| 143 |
-
DEFAULT_DETECTOR_MODEL=mock
|
| 144 |
-
|
| 145 |
-
# Redis (for future use)
|
| 146 |
-
REDIS_ENABLED=False
|
| 147 |
-
REDIS_URL=redis://localhost:6379
|
| 148 |
-
|
| 149 |
-
# Logging
|
| 150 |
-
LOG_LEVEL=INFO
|
| 151 |
-
LOG_FILE=
|
| 152 |
-
```
|
| 153 |
-
|
| 154 |
-
## π― Adding New ML Models
|
| 155 |
-
|
| 156 |
-
The architecture supports easy addition of new detector models:
|
| 157 |
-
|
| 158 |
-
1. **Create a new detector class** in `app/services/detector/`:
|
| 159 |
-
|
| 160 |
-
```python
|
| 161 |
-
# app/services/detector/deepseek.py
|
| 162 |
-
from app.services.detector.base import BaseDetector
|
| 163 |
-
|
| 164 |
-
class DeepseekDetector(BaseDetector):
|
| 165 |
-
def __init__(self):
|
| 166 |
-
super().__init__("deepseek")
|
| 167 |
-
|
| 168 |
-
async def detect(self, file_bytes: bytes) -> dict:
|
| 169 |
-
# Your ML model implementation
|
| 170 |
-
return {
|
| 171 |
-
"is_deepfake": False,
|
| 172 |
-
"confidence": 0.95,
|
| 173 |
-
"analysis_time": 2.5
|
| 174 |
-
}
|
| 175 |
-
```
|
| 176 |
-
|
| 177 |
-
2. **Register the detector** in `app/services/detector/__init__.py`:
|
| 178 |
-
|
| 179 |
-
```python
|
| 180 |
-
def get_detector(model_name: str = "mock") -> BaseDetector:
|
| 181 |
-
detectors = {
|
| 182 |
-
"mock": MockDetector,
|
| 183 |
-
"deepseek": DeepseekDetector, # Add this
|
| 184 |
-
# ... more models
|
| 185 |
-
}
|
| 186 |
-
# ... rest of code
|
| 187 |
-
```
|
| 188 |
-
|
| 189 |
-
3. **Update `.env.example`** to document the new model
|
| 190 |
-
|
| 191 |
-
## π¦ Future Redis Integration
|
| 192 |
-
|
| 193 |
-
The queue service is designed to support Redis task queuing without major refactoring:
|
| 194 |
-
|
| 195 |
-
1. Set `REDIS_ENABLED=True` in `.env`
|
| 196 |
-
2. Set correct `REDIS_URL`
|
| 197 |
-
3. The queue service will automatically use Redis for task management
|
| 198 |
-
|
| 199 |
-
Redis support will enable:
|
| 200 |
-
- Asynchronous task processing
|
| 201 |
-
- Task result caching
|
| 202 |
-
- Improved scalability for high-volume requests
|
| 203 |
-
|
| 204 |
-
## π Logging
|
| 205 |
-
|
| 206 |
-
Logs are configured in `app/core/logging_config.py`. By default:
|
| 207 |
-
- Level: INFO
|
| 208 |
-
- Output: Console
|
| 209 |
-
- Rotation: Automatic (if LOG_FILE is set)
|
| 210 |
-
|
| 211 |
-
Configure logging level via environment:
|
| 212 |
-
```bash
|
| 213 |
-
LOG_LEVEL=DEBUG # For verbose logging
|
| 214 |
-
```
|
| 215 |
-
|
| 216 |
-
## π§ͺ Testing the API
|
| 217 |
|
| 218 |
### Using curl:
|
| 219 |
```bash
|
|
@@ -222,34 +98,6 @@ curl -X POST http://localhost:8000/analyze \
|
|
| 222 |
-d '{"file_url": "https://example.com/video.mp4"}'
|
| 223 |
```
|
| 224 |
|
| 225 |
-
### Using Python requests:
|
| 226 |
-
```python
|
| 227 |
-
import requests
|
| 228 |
-
|
| 229 |
-
response = requests.post(
|
| 230 |
-
"http://localhost:8000/analyze",
|
| 231 |
-
json={"file_url": "https://example.com/video.mp4"}
|
| 232 |
-
)
|
| 233 |
-
print(response.json())
|
| 234 |
-
```
|
| 235 |
-
|
| 236 |
-
### Using httpx (async):
|
| 237 |
-
```python
|
| 238 |
-
import httpx
|
| 239 |
-
import asyncio
|
| 240 |
-
|
| 241 |
-
async def test():
|
| 242 |
-
async with httpx.AsyncClient() as client:
|
| 243 |
-
response = await client.post(
|
| 244 |
-
"http://localhost:8000/analyze",
|
| 245 |
-
json={"file_url": "https://example.com/video.mp4"}
|
| 246 |
-
)
|
| 247 |
-
print(response.json())
|
| 248 |
-
|
| 249 |
-
asyncio.run(test())
|
| 250 |
-
```
|
| 251 |
-
|
| 252 |
-
## π Error Handling
|
| 253 |
|
| 254 |
The API provides comprehensive error handling:
|
| 255 |
|
|
@@ -283,50 +131,3 @@ The API provides comprehensive error handling:
|
|
| 283 |
}
|
| 284 |
```
|
| 285 |
|
| 286 |
-
## π§ Troubleshooting
|
| 287 |
-
|
| 288 |
-
**Port already in use:**
|
| 289 |
-
```bash
|
| 290 |
-
# Change port via environment variable
|
| 291 |
-
PORT=8001 python main.py
|
| 292 |
-
```
|
| 293 |
-
|
| 294 |
-
**Import errors:**
|
| 295 |
-
```bash
|
| 296 |
-
# Ensure you're in the backend directory and have activated venv
|
| 297 |
-
cd backend
|
| 298 |
-
source venv/bin/activate # or venv\Scripts\activate on Windows
|
| 299 |
-
pip install -r requirements.txt
|
| 300 |
-
```
|
| 301 |
-
|
| 302 |
-
**Timeout issues:**
|
| 303 |
-
```bash
|
| 304 |
-
# Increase timeout for slow downloads
|
| 305 |
-
DOWNLOAD_TIMEOUT=60 python main.py
|
| 306 |
-
```
|
| 307 |
-
|
| 308 |
-
## π¦ Dependencies
|
| 309 |
-
|
| 310 |
-
- **FastAPI**: Modern async web framework
|
| 311 |
-
- **Uvicorn**: ASGI server
|
| 312 |
-
- **Pydantic**: Data validation and settings
|
| 313 |
-
- **httpx**: Async HTTP client for file downloads
|
| 314 |
-
|
| 315 |
-
See `requirements.txt` for exact versions.
|
| 316 |
-
|
| 317 |
-
## π License
|
| 318 |
-
|
| 319 |
-
This project is part of the DiscordBot backend service.
|
| 320 |
-
|
| 321 |
-
## π€ Contributing
|
| 322 |
-
|
| 323 |
-
To add new features or models:
|
| 324 |
-
|
| 325 |
-
1. Follow the existing code structure
|
| 326 |
-
2. Implement abstract base classes for new functionality
|
| 327 |
-
3. Add comprehensive logging
|
| 328 |
-
4. Update documentation and examples
|
| 329 |
-
|
| 330 |
-
## π§ Support
|
| 331 |
-
|
| 332 |
-
For issues or questions, please refer to the project documentation or contact the development team.
|
|
|
|
| 1 |
# Deepfake Detection Service Backend
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
### Prerequisites
|
| 4 |
- Python 3.8+
|
| 5 |
- pip or conda
|
|
|
|
| 90 |
- `408 Request Timeout`: File download timed out
|
| 91 |
- `500 Internal Server Error`: Server error during analysis
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
### Using curl:
|
| 95 |
```bash
|
|
|
|
| 98 |
-d '{"file_url": "https://example.com/video.mp4"}'
|
| 99 |
```
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
The API provides comprehensive error handling:
|
| 103 |
|
|
|
|
| 131 |
}
|
| 132 |
```
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/app/__init__.py
CHANGED
|
@@ -1,36 +1,13 @@
|
|
| 1 |
-
"""Deepfake Detection Service Application"""
|
| 2 |
-
|
| 3 |
from fastapi import FastAPI
|
| 4 |
from app.api.routes import router as api_router
|
| 5 |
from app.core.logging_config import setup_logging
|
| 6 |
-
from app.core.config import Settings
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
"""Create and configure the FastAPI application."""
|
| 13 |
-
setup_logging()
|
| 14 |
-
|
| 15 |
-
app = FastAPI(
|
| 16 |
-
title="Deepfake Detection Service",
|
| 17 |
-
description="Backend service for deepfake detection with support for multiple ML models",
|
| 18 |
-
version=__version__,
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
# Include API routes
|
| 22 |
-
app.include_router(api_router)
|
| 23 |
-
|
| 24 |
-
@app.on_event("startup")
|
| 25 |
-
async def startup_event():
|
| 26 |
-
import logging
|
| 27 |
-
logger = logging.getLogger(__name__)
|
| 28 |
-
logger.info("Deepfake Detection Service is starting up...")
|
| 29 |
-
|
| 30 |
-
@app.on_event("shutdown")
|
| 31 |
-
async def shutdown_event():
|
| 32 |
-
import logging
|
| 33 |
-
logger = logging.getLogger(__name__)
|
| 34 |
-
logger.info("Deepfake Detection Service is shutting down...")
|
| 35 |
-
|
| 36 |
-
return app
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from app.api.routes import router as api_router
|
| 3 |
from app.core.logging_config import setup_logging
|
|
|
|
| 4 |
|
| 5 |
+
setup_logging()
|
| 6 |
|
| 7 |
+
app = FastAPI(
|
| 8 |
+
title="Deepfake Detection Service",
|
| 9 |
+
description="Backend service for deepfake detection with support for multiple ML models",
|
| 10 |
+
version="1.0.0",
|
| 11 |
+
)
|
| 12 |
|
| 13 |
+
app.include_router(api_router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/app/api/routes.py
CHANGED
|
@@ -77,6 +77,7 @@ async def analyze(request: AnalysisRequest) -> AnalysisResponse:
|
|
| 77 |
f"using model: {detector_model}"
|
| 78 |
)
|
| 79 |
|
|
|
|
| 80 |
try:
|
| 81 |
try:
|
| 82 |
detector = get_detector(detector_model)
|
|
|
|
| 77 |
f"using model: {detector_model}"
|
| 78 |
)
|
| 79 |
|
| 80 |
+
|
| 81 |
try:
|
| 82 |
try:
|
| 83 |
detector = get_detector(detector_model)
|
backend/main.py
CHANGED
|
@@ -1,35 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
This is the main entry point for the FastAPI application.
|
| 5 |
-
Run this file directly to start the server on localhost:8000
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
import logging
|
| 9 |
-
from app import create_app
|
| 10 |
-
from app.core.config import get_settings
|
| 11 |
-
|
| 12 |
-
logger = logging.getLogger(__name__)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def main():
|
| 16 |
-
"""Initialize and run the FastAPI application."""
|
| 17 |
-
settings = get_settings()
|
| 18 |
-
app = create_app()
|
| 19 |
-
|
| 20 |
-
import uvicorn
|
| 21 |
-
|
| 22 |
-
logger.info(
|
| 23 |
-
f"Starting {settings.APP_NAME} on {settings.HOST}:{settings.PORT}"
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
uvicorn.run(
|
| 27 |
-
app,
|
| 28 |
-
host=settings.HOST,
|
| 29 |
-
port=settings.PORT,
|
| 30 |
-
log_level=settings.LOG_LEVEL.lower(),
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
-
|
|
|
|
| 1 |
+
import uvicorn
|
| 2 |
+
from app import app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
if __name__ == "__main__":
|
| 5 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
backend/run.bat
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
@echo off
|
| 2 |
-
REM Deepfake Detection Service - Windows Run Script
|
| 3 |
-
|
| 4 |
-
echo Starting Deepfake Detection Service Backend...
|
| 5 |
-
python main.py
|
| 6 |
-
pause
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/setup.py
CHANGED
|
@@ -1,10 +1,3 @@
|
|
| 1 |
-
#!/usr/bin/env python
|
| 2 |
-
"""
|
| 3 |
-
Setup script for the Deepfake Detection Service backend.
|
| 4 |
-
|
| 5 |
-
Run: python setup.py
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
import os
|
| 9 |
import sys
|
| 10 |
import subprocess
|
|
@@ -28,12 +21,6 @@ def main():
|
|
| 28 |
print("\n" + "="*60)
|
| 29 |
print("π Deepfake Detection Service - Backend Setup")
|
| 30 |
print("="*60)
|
| 31 |
-
|
| 32 |
-
# Check Python version
|
| 33 |
-
if sys.version_info < (3, 8):
|
| 34 |
-
print("β Python 3.8 or higher is required")
|
| 35 |
-
sys.exit(1)
|
| 36 |
-
|
| 37 |
print(f"β
Python version: {sys.version}")
|
| 38 |
|
| 39 |
# Determine OS for venv activation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import subprocess
|
|
|
|
| 21 |
print("\n" + "="*60)
|
| 22 |
print("π Deepfake Detection Service - Backend Setup")
|
| 23 |
print("="*60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
print(f"β
Python version: {sys.version}")
|
| 25 |
|
| 26 |
# Determine OS for venv activation
|