Spaces:
Sleeping
Sleeping
HanningChen
commited on
Commit
·
696fa29
1
Parent(s):
a80f35b
backend only code
Browse files- webui/app.py +17 -4
webui/app.py
CHANGED
|
@@ -16,6 +16,19 @@ from fastapi.templating import Jinja2Templates
|
|
| 16 |
from webui.runner import ModelRunner
|
| 17 |
from webui.weights import get_weights_dir
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
PROJECT_ROOT = Path(__file__).resolve().parents[1] # repo root
|
| 20 |
WEBUI_DIR = Path(__file__).resolve().parent
|
| 21 |
UPLOAD_DIR = WEBUI_DIR / "uploads"
|
|
@@ -23,12 +36,12 @@ RESULT_DIR = WEBUI_DIR / "results"
|
|
| 23 |
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
| 24 |
RESULT_DIR.mkdir(parents=True, exist_ok=True)
|
| 25 |
|
| 26 |
-
app = FastAPI()
|
| 27 |
-
templates = Jinja2Templates(directory=str(WEBUI_DIR / "templates"))
|
| 28 |
-
|
| 29 |
-
app.mount("/static", StaticFiles(directory=str(WEBUI_DIR / "static")), name="static")
|
| 30 |
app.mount("/results", StaticFiles(directory=str(RESULT_DIR)), name="results")
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# ---- weights repo ----
|
| 33 |
WEIGHTS_REPO = os.getenv("TASKCLIP_WEIGHTS_REPO", "BiasLab2025/taskclip-weights")
|
| 34 |
WEIGHTS_DIR = get_weights_dir(WEIGHTS_REPO)
|
|
|
|
| 16 |
from webui.runner import ModelRunner
|
| 17 |
from webui.weights import get_weights_dir
|
| 18 |
|
| 19 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 20 |
+
|
| 21 |
+
app = FastAPI()
|
| 22 |
+
|
| 23 |
+
# CORS for local frontend
|
| 24 |
+
app.add_middleware(
|
| 25 |
+
CORSMiddleware,
|
| 26 |
+
allow_origins=["http://localhost:8000", "http://127.0.0.1:8000", "null"],
|
| 27 |
+
allow_credentials=False,
|
| 28 |
+
allow_methods=["*"],
|
| 29 |
+
allow_headers=["*"],
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
PROJECT_ROOT = Path(__file__).resolve().parents[1] # repo root
|
| 33 |
WEBUI_DIR = Path(__file__).resolve().parent
|
| 34 |
UPLOAD_DIR = WEBUI_DIR / "uploads"
|
|
|
|
| 36 |
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
|
| 37 |
RESULT_DIR.mkdir(parents=True, exist_ok=True)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
app.mount("/results", StaticFiles(directory=str(RESULT_DIR)), name="results")
|
| 40 |
|
| 41 |
+
@app.get("/health")
|
| 42 |
+
def health():
|
| 43 |
+
return {"ok": True}
|
| 44 |
+
|
| 45 |
# ---- weights repo ----
|
| 46 |
WEIGHTS_REPO = os.getenv("TASKCLIP_WEIGHTS_REPO", "BiasLab2025/taskclip-weights")
|
| 47 |
WEIGHTS_DIR = get_weights_dir(WEIGHTS_REPO)
|