Spaces:
Running
Running
| from __future__ import annotations | |
| import logging | |
| import shutil | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from app.config import settings | |
| from app.routes.verify_image import router as verify_image_router | |
| from app.services.image_detector import image_detector | |
| logging.basicConfig( | |
| level=getattr(logging, settings.log_level.upper(), logging.INFO), | |
| format="%(asctime)s %(levelname)s %(name)s - %(message)s", | |
| ) | |
| app = FastAPI( | |
| title="BitCheck Image Verification API", | |
| description="Risk-based image authenticity and provenance verification backend.", | |
| version="0.1.0", | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.cors_origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(verify_image_router) | |
| app.mount("/outputs", StaticFiles(directory=str(settings.outputs_dir)), name="outputs") | |
| def startup() -> None: | |
| image_detector.load() | |
| def root() -> dict[str, str]: | |
| return {"service": "BitCheck Image Verification API", "status": "running"} | |
| def test_client() -> FileResponse: | |
| return FileResponse("test-client.html") | |
| def health() -> dict[str, object]: | |
| try: | |
| import pytesseract | |
| pytesseract.get_tesseract_version() | |
| ocr_available = True | |
| except Exception: | |
| ocr_available = False | |
| return { | |
| "status": "ok", | |
| "service": "BitCheck Image Verification API", | |
| "classifier_loaded": image_detector.is_loaded, | |
| "ocr_available": ocr_available, | |
| "c2pa_available": shutil.which("c2patool") is not None, | |
| "device": str(image_detector.device), | |
| } | |