Update detection_api.py
Browse files- detection_api.py +23 -1
detection_api.py
CHANGED
|
@@ -16,7 +16,7 @@ import logging
|
|
| 16 |
import hashlib
|
| 17 |
import time
|
| 18 |
from functools import lru_cache
|
| 19 |
-
|
| 20 |
from main import ContentModerator
|
| 21 |
|
| 22 |
# Setup logging
|
|
@@ -84,7 +84,29 @@ executor = ThreadPoolExecutor(max_workers=config.MAX_WORKERS)
|
|
| 84 |
# Video Optimizer Class
|
| 85 |
class VideoOptimizer:
|
| 86 |
"""Optimized video processing for CPU environments"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
|
|
|
|
|
|
| 88 |
def __init__(self):
|
| 89 |
self.frame_cache = {}
|
| 90 |
self.cache_size = 20
|
|
|
|
| 16 |
import hashlib
|
| 17 |
import time
|
| 18 |
from functools import lru_cache
|
| 19 |
+
from gunicorn.app.base import BaseApplication
|
| 20 |
from main import ContentModerator
|
| 21 |
|
| 22 |
# Setup logging
|
|
|
|
| 84 |
# Video Optimizer Class
|
| 85 |
class VideoOptimizer:
|
| 86 |
"""Optimized video processing for CPU environments"""
|
| 87 |
+
def StandaloneApplication(app, options=None):
|
| 88 |
+
"""Hàm tạo Gunicorn Application từ FastAPI app"""
|
| 89 |
+
from gunicorn.app.base import BaseApplication
|
| 90 |
+
|
| 91 |
+
class _App(BaseApplication):
|
| 92 |
+
def __init__(self, app, options=None):
|
| 93 |
+
self.options = options or {}
|
| 94 |
+
self.application = app
|
| 95 |
+
super().__init__()
|
| 96 |
+
|
| 97 |
+
def load_config(self):
|
| 98 |
+
config = {
|
| 99 |
+
key: value for key, value in self.options.items()
|
| 100 |
+
if key in self.cfg.settings and value is not None
|
| 101 |
+
}
|
| 102 |
+
for key, value in config.items():
|
| 103 |
+
self.cfg.set(key.lower(), value)
|
| 104 |
+
|
| 105 |
+
def load(self):
|
| 106 |
+
return self.application
|
| 107 |
|
| 108 |
+
return _App(app, options)
|
| 109 |
+
|
| 110 |
def __init__(self):
|
| 111 |
self.frame_cache = {}
|
| 112 |
self.cache_size = 20
|