Spaces:
Sleeping
Sleeping
File size: 1,266 Bytes
cd9e104 59f3fa8 cd9e104 |
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 |
from app.api.api_routes import router
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import os, subprocess, textwrap
from huggingface_hub import scan_cache_dir
def _audit_disk():
try:
cmd = "du -h -d 2 /app /tmp /home/user ~/.cache /root/.cache /usr/local/lib/python* /var | sort -h | tail -n 25"
print("\n==== DISK TOP ====")
print(subprocess.check_output(cmd, shell=True, text=True))
except Exception as e:
print("du failed:", e)
try:
print("\n==== HF CACHE ====")
r = scan_cache_dir() # scans TRANSFORMERS/HF caches
print("HF cache on disk:", r.size_on_disk_str)
for d in sorted(r.repos, key=lambda x: -x.size_on_disk)[:10]:
print(f"{d.repo_id}: {d.size_on_disk_str}")
except Exception as e:
print("scan_cache_dir failed:", e)
_audit_disk() # call once at startup
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Update with frontend domain in prod
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(router)
@app.get("/health")
def health_check():
return {"status": "ok"}
@app.get("/")
def read_root():
return {"status": "ok"} |