JJTsao's picture
Update main.py
59f3fa8 verified
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"}