Spaces:
Sleeping
Sleeping
File size: 2,390 Bytes
6e02ff7 d80e487 6e02ff7 c86d2cd 6e02ff7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import logging
import os
# Pop HF Spaces proxy env vars BEFORE any other imports to prevent supabase/httpx from breaking
for key in ["HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"]:
os.environ.pop(key, None)
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routes import skills, matches, chat
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""
Load the sentence-transformers model once at startup.
Importing embedder triggers the module-level SentenceTransformer() call.
"""
logger.info("Loading sentence-transformers model...")
import services.embedder # noqa: F401 β side-effect import triggers model load
logger.info("Model ready. SkillBridge API is live.")
yield
logger.info("Shutting down.")
app = FastAPI(
title="SkillBridge API",
version="1.0.0",
lifespan=lifespan,
)
# ββ CORS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:3000",
"https://skillbridge9.vercel.app",
"https://*.vercel.app",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ββ Routers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
app.include_router(skills.router)
app.include_router(matches.router)
app.include_router(chat.router)
# ββ Health check ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@app.get("/health", tags=["health"])
async def health() -> dict:
return {"status": "ok"}
# ββ Entry point (used by Dockerfile CMD) βββββββββββββββββββββββββββββββββββββ
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=False)
|