ThesisBackend / app /main.py
AdarshRajDS
stable multimodal supabase ingestion milestone
5484978
import os
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from app.api.routes import rag, visualize, grading, upload
from app.api.routes import images
from app.api.routes import debug_storage
# ✅ Use persistent storage on HF, local folder otherwise
BASE_DATA_DIR = os.getenv("HF_HOME", ".")
OUTPUT_DIR = os.path.join(BASE_DATA_DIR, "outputs")
# ✅ Create the folder BEFORE mounting
os.makedirs(OUTPUT_DIR, exist_ok=True)
app = FastAPI(title="Multimodal RAG API")
# CORS: comma-separated list in env, e.g.
# ALLOWED_ORIGINS=https://adarshds-thesisfrontend.hf.space,http://localhost:3000
origins_env = os.getenv("ALLOWED_ORIGINS", "")
allowed_origins = [o.strip() for o in origins_env.split(",") if o.strip()]
# Safe defaults for current frontend + local dev when env is not set
if not allowed_origins:
allowed_origins = [
"https://adarshds-thesisfrontend.hf.space",
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=allowed_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(rag.router)
app.include_router(visualize.router)
app.include_router(grading.router)
app.include_router(upload.router)
app.include_router(images.router)
app.include_router(debug_storage.router)
# ✅ Mount the real path (not hardcoded "outputs")
app.mount("/outputs", StaticFiles(directory=OUTPUT_DIR), name="outputs")
@app.get("/")
def root():
return {"status": "running"}