Spaces:
Runtime error
Runtime error
| import os | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import FileResponse | |
| from app.api import router as api_router | |
| app = FastAPI( | |
| title="PII Masker for Docs", | |
| description="An API to detect and redact Personally Identifiable Information (PII) from PDF and DOCX documents using a BERT-based NER model.", | |
| version="1.0", | |
| ) | |
| # --- Middleware --- | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # --- API Router --- | |
| # All API logic is now cleanly handled by the router from app/api.py | |
| app.include_router(api_router) | |
| # --- Frontend Serving --- | |
| frontend_path = os.path.join(os.path.dirname(__file__), "frontend") | |
| if os.path.exists(frontend_path): | |
| # Mount the 'static' directory to serve frontend files like CSS and JS | |
| app.mount("/static", StaticFiles(directory=frontend_path), name="static") | |
| # Serve the main index.html for the root URL | |
| async def serve_index(): | |
| return FileResponse(os.path.join(frontend_path, "index.html")) | |
| # --- Main Entry Point --- | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=8000) |