Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app/main.py +22 -6
- requirements.txt +15 -14
app/main.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -6,7 +7,17 @@ from app.core.config import settings
|
|
| 6 |
from app.core.db import ensure_indexes
|
| 7 |
from app.routers import alerts, auth, devices, keys, policy, reviews, screenshots
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
app.add_middleware(
|
| 12 |
CORSMiddleware,
|
|
@@ -26,11 +37,16 @@ app.include_router(reviews.router, prefix=settings.api_prefix)
|
|
| 26 |
app.mount(settings.media_prefix, StaticFiles(directory=settings.storage_dir), name="media")
|
| 27 |
|
| 28 |
|
| 29 |
-
@app.on_event("startup")
|
| 30 |
-
async def on_startup() -> None:
|
| 31 |
-
await ensure_indexes()
|
| 32 |
-
|
| 33 |
-
|
| 34 |
@app.get("/health")
|
| 35 |
def health() -> dict[str, str]:
|
| 36 |
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from contextlib import asynccontextmanager
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 7 |
from app.core.db import ensure_indexes
|
| 8 |
from app.routers import alerts, auth, devices, keys, policy, reviews, screenshots
|
| 9 |
|
| 10 |
+
|
| 11 |
+
@asynccontextmanager
|
| 12 |
+
async def lifespan(app: FastAPI):
|
| 13 |
+
"""Lifespan context manager for startup/shutdown events."""
|
| 14 |
+
# Startup
|
| 15 |
+
await ensure_indexes()
|
| 16 |
+
yield
|
| 17 |
+
# Shutdown (cleanup if needed)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
app = FastAPI(title=settings.app_name, lifespan=lifespan)
|
| 21 |
|
| 22 |
app.add_middleware(
|
| 23 |
CORSMiddleware,
|
|
|
|
| 37 |
app.mount(settings.media_prefix, StaticFiles(directory=settings.storage_dir), name="media")
|
| 38 |
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
@app.get("/health")
|
| 41 |
def health() -> dict[str, str]:
|
| 42 |
return {"status": "ok"}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
import uvicorn
|
| 47 |
+
uvicorn.run(
|
| 48 |
+
"app.main:app",
|
| 49 |
+
host="0.0.0.0",
|
| 50 |
+
port=7860,
|
| 51 |
+
reload=False,
|
| 52 |
+
)
|
requirements.txt
CHANGED
|
@@ -1,14 +1,15 @@
|
|
| 1 |
-
fastapi
|
| 2 |
-
uvicorn[standard]
|
| 3 |
-
pydantic
|
| 4 |
-
pydantic-settings
|
| 5 |
-
python-multipart
|
| 6 |
-
motor
|
| 7 |
-
pymongo
|
| 8 |
-
python-dotenv
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
pydantic
|
| 4 |
+
pydantic-settings
|
| 5 |
+
python-multipart
|
| 6 |
+
motor
|
| 7 |
+
pymongo
|
| 8 |
+
python-dotenv
|
| 9 |
+
bcrypt
|
| 10 |
+
Pillow
|
| 11 |
+
timm
|
| 12 |
+
torch
|
| 13 |
+
safetensors
|
| 14 |
+
easyocr
|
| 15 |
+
huggingface_hub
|