Commit
·
80b99f5
1
Parent(s):
99d257e
feat(auth): login to Hugging Face Hub via HUGGINGFACE_HUB_TOKEN; set HF_TOKEN/TOKEN; default OMP_NUM_THREADS=1
Browse files- api_server.py +15 -0
api_server.py
CHANGED
|
@@ -16,6 +16,7 @@ from fastapi.responses import FileResponse, StreamingResponse, JSONResponse
|
|
| 16 |
import logging
|
| 17 |
from logging.handlers import BufferingHandler
|
| 18 |
from firebase_app_check import verify_app_check_token, verify_firebase_id_token
|
|
|
|
| 19 |
|
| 20 |
# Import face swap functionality
|
| 21 |
import sys
|
|
@@ -30,6 +31,20 @@ app = FastAPI(title="Face Swap Video API", version="1.0.0")
|
|
| 30 |
API_PASSWORD = os.getenv("API_PASSWORD", "logicgo_videoswap@153")
|
| 31 |
security = HTTPBearer()
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def verify_api_key(credentials: HTTPAuthorizationCredentials = Security(security)):
|
| 34 |
"""Verify API key from Bearer token.
|
| 35 |
|
|
|
|
| 16 |
import logging
|
| 17 |
from logging.handlers import BufferingHandler
|
| 18 |
from firebase_app_check import verify_app_check_token, verify_firebase_id_token
|
| 19 |
+
from huggingface_hub import login as hf_login
|
| 20 |
|
| 21 |
# Import face swap functionality
|
| 22 |
import sys
|
|
|
|
| 31 |
API_PASSWORD = os.getenv("API_PASSWORD", "logicgo_videoswap@153")
|
| 32 |
security = HTTPBearer()
|
| 33 |
|
| 34 |
+
# Authenticate Hugging Face Hub for model downloads (private/rate-limited)
|
| 35 |
+
_hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN") or os.getenv("HF_TOKEN")
|
| 36 |
+
if _hf_token:
|
| 37 |
+
try:
|
| 38 |
+
hf_login(token=_hf_token) # nosec - token provided via env
|
| 39 |
+
except Exception:
|
| 40 |
+
pass
|
| 41 |
+
# Also expose legacy env names some utils expect
|
| 42 |
+
os.environ.setdefault("HF_TOKEN", _hf_token)
|
| 43 |
+
os.environ.setdefault("TOKEN", _hf_token)
|
| 44 |
+
|
| 45 |
+
# Ensure sane threads to avoid libgomp warnings
|
| 46 |
+
os.environ.setdefault("OMP_NUM_THREADS", "1")
|
| 47 |
+
|
| 48 |
def verify_api_key(credentials: HTTPAuthorizationCredentials = Security(security)):
|
| 49 |
"""Verify API key from Bearer token.
|
| 50 |
|