Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,13 @@ import requests
|
|
| 13 |
from pathlib import Path
|
| 14 |
import uvicorn
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Configure logging
|
| 19 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -33,6 +39,11 @@ app.add_middleware(
|
|
| 33 |
async def root():
|
| 34 |
return {"message": "Welcome to the Face Swap API! Use /swap-face/ to swap faces or /docs to test the API."}
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Global flag to prevent multiple downloads
|
| 37 |
MODEL_DOWNLOADED = False
|
| 38 |
|
|
@@ -64,7 +75,7 @@ def download_model():
|
|
| 64 |
logger.info("Model already exists at: %s", model_path)
|
| 65 |
MODEL_DOWNLOADED = True
|
| 66 |
|
| 67 |
-
# Use lifespan event handler
|
| 68 |
@asynccontextmanager
|
| 69 |
async def lifespan(app: FastAPI):
|
| 70 |
# Startup code
|
|
|
|
| 13 |
from pathlib import Path
|
| 14 |
import uvicorn
|
| 15 |
|
| 16 |
+
# Initialize FastAPI with explicit docs settings
|
| 17 |
+
app = FastAPI(
|
| 18 |
+
title="Face Swap API",
|
| 19 |
+
description="API for swapping faces in images.",
|
| 20 |
+
docs_url="/docs", # Explicitly set docs URL
|
| 21 |
+
redoc_url="/redoc", # Explicitly set redoc URL
|
| 22 |
+
)
|
| 23 |
|
| 24 |
# Configure logging
|
| 25 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 39 |
async def root():
|
| 40 |
return {"message": "Welcome to the Face Swap API! Use /swap-face/ to swap faces or /docs to test the API."}
|
| 41 |
|
| 42 |
+
# Add a health check endpoint
|
| 43 |
+
@app.get("/health")
|
| 44 |
+
async def health_check():
|
| 45 |
+
return {"status": "healthy"}
|
| 46 |
+
|
| 47 |
# Global flag to prevent multiple downloads
|
| 48 |
MODEL_DOWNLOADED = False
|
| 49 |
|
|
|
|
| 75 |
logger.info("Model already exists at: %s", model_path)
|
| 76 |
MODEL_DOWNLOADED = True
|
| 77 |
|
| 78 |
+
# Use lifespan event handler
|
| 79 |
@asynccontextmanager
|
| 80 |
async def lifespan(app: FastAPI):
|
| 81 |
# Startup code
|