-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (56 loc) · 2.17 KB
/
Copy pathmain.py
File metadata and controls
68 lines (56 loc) · 2.17 KB
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
64
65
66
67
68
"""
Azulweb — Backend FastAPI
Start with: uvicorn main:app --reload --port 8000
"""
import logging
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from routers import crop, find, process, retrieve, workspace
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
)
logger = logging.getLogger(__name__)
uvicorn_logger = logging.getLogger("uvicorn")
uvicorn_logger.handlers = logging.getLogger().handlers
uvicorn_logger.setLevel(logging.INFO)
app = FastAPI(
title="Azulero GUI API",
description="Backend for Azulweb - Azulero GUI (Euclid color images)",
version="0.0.1",
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Routers
app.include_router(workspace.router, prefix="/workspace", tags=["Workspace"])
app.include_router(find.router, prefix="/find", tags=["Find"])
app.include_router(retrieve.router, prefix="/retrieve", tags=["Retrieve"])
app.include_router(crop.router, prefix="/crop", tags=["Crop"])
app.include_router(process.router, prefix="/process", tags=["Process"])
# Serve images/videos
outputs_dir = Path("workspace")
outputs_dir.mkdir(exist_ok=True)
app.mount("/workspace", StaticFiles(directory="workspace"), name="workspace")
app.mount("/", StaticFiles(directory="frontend", html=True), name="frontend")
@app.get("/health", tags=["Health"])
def health() -> dict[str, str]:
"""Check azulero installation."""
import subprocess
try:
result = subprocess.run(["azul", "--version"], capture_output=True, text=True, timeout=5)
version = result.stdout.strip() or result.stderr.strip()
logger.info(f"Azulero version: {version}")
return {"status": "ok", "azulero_version": version}
except FileNotFoundError:
logger.warning("Azulero not found")
return {"status": "error", "detail": "azulero not found — pip install azulero"}
except Exception as e:
logger.exception("Unexpected error while checking azulero")
return {"status": "error", "detail": str(e)}