File size: 2,119 Bytes
feeb227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""

Embedded server that serves React client and OCR API

"""
import os
import sys
from pathlib import Path
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
import uvicorn

# Import the main app and its routes
from app import app as ocr_app

# Create main FastAPI app
main_app = FastAPI(title="SPaCial AI OCR - Portable Edition")

# Include all OCR API routes directly (not mounted under /api)
# This makes the API available at /ocr/process, /export/pdf, etc.
main_app.include_router(ocr_app.router)

# Serve React client static files
static_path = Path(__file__).parent / "static"
if static_path.exists():
    # Mount assets directory for JS/CSS files
    assets_path = static_path / "assets"
    if assets_path.exists():
        main_app.mount("/assets", StaticFiles(directory=str(assets_path)), name="assets")

@main_app.get("/vite.svg")
async def serve_vite_svg():
    """Serve vite.svg"""
    svg_file = Path(__file__).parent / "static" / "vite.svg"
    if svg_file.exists():
        return FileResponse(svg_file)
    return FileResponse(Path(__file__).parent / "static" / "index.html")

@main_app.get("/")
async def serve_client():
    """Serve the React client"""
    client_file = Path(__file__).parent / "static" / "index.html"
    if client_file.exists():
        return FileResponse(client_file)
    return {"message": "SPaCial AI OCR Server is running", "docs": "/docs"}

@main_app.get("/health")
async def health_check():
    """Health check endpoint"""
    return {"status": "healthy", "version": "1.0.0"}

if __name__ == "__main__":
    # Get port from environment or use default
    port = int(os.environ.get("PORT", 8000))
    host = os.environ.get("HOST", "127.0.0.1")
    
    print(f"Starting SPaCial AI OCR Server...")
    print(f"Server: http://{host}:{port}")
    print(f"Client: http://{host}:{port}")
    print(f"API Docs: http://{host}:{port}/docs")
    print("\nPress Ctrl+C to stop")
    
    uvicorn.run(main_app, host=host, port=port, log_level="info")