File size: 1,320 Bytes
98abe61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
    @app.get("/", include_in_schema=False)
    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)