Gifted-oNe's picture
feat: Add Website Parser, LLM Summarization, and Document Types
2e6d372
Raw
History Blame Contribute Delete
1.98 kB
"""
Puff n Parse — FastAPI Backend Application
Main entry point for the extraction and export API.
Configures CORS for the React frontend and mounts all routers.
"""
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routers import upload, export, website
# Environment configuration
FRONTEND_URL = os.getenv("FRONTEND_URL", "http://localhost:5173")
API_PORT = int(os.getenv("PORT", "7860"))
app = FastAPI(
title="Puff n Parse API",
description="PDF parsing and OCR extraction engine for Puff n Parse / OCRuserious",
version="1.0.0",
)
# CORS — allow the React frontend to call this API
app.add_middleware(
CORSMiddleware,
allow_origins=[
FRONTEND_URL,
"http://localhost:5173", # Vite dev server
"http://localhost:3000", # Alternative dev port
"https://*.netlify.app", # Production Netlify
"https://*.vercel.app", # Production Vercel
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["Content-Disposition"],
)
# Mount routers
app.include_router(upload.router)
app.include_router(export.router)
app.include_router(website.router)
@app.get("/")
async def root():
"""Health check and API info."""
return {
"name": "Puff n Parse API",
"version": "1.0.0",
"status": "healthy",
"engines": {
"pdf_parser": "pdfplumber",
"ocr_engine": "EasyOCR (Afrikaans, English, Swahili, French, Portuguese)",
"image_preprocessor": "OpenCV",
},
"export_formats": ["csv", "xlsx", "docx", "pdf"],
}
@app.get("/api/health")
async def health_check():
"""Simple health check endpoint."""
return {"status": "ok"}
# For running directly: python -m main
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
port=API_PORT,
reload=True,
)