File size: 1,709 Bytes
f440f03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
"""FastAPI lietojumprogramma — galvenais ieejas punkts priekš Rust backend."""

from contextlib import asynccontextmanager

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse

from maris_core.runtime import (
    configure_huggingface_environment,
    is_reload_enabled,
    resolve_host,
    resolve_port,
)

configure_huggingface_environment()

from maris_core.api import router  # noqa: E402
from maris_core.text.generate import get_text_model_readiness, warm_text_model_runtime  # noqa: E402


@asynccontextmanager
async def lifespan(_: FastAPI):
    warm_text_model_runtime()
    yield


app = FastAPI(
    title="Maris AI Core Python",
    description="MI kodols: teksts, attēli, audio, video, kods, aģents",
    version="0.1.0",
    lifespan=lifespan,
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(router, prefix="/v1")


@app.get("/health")
async def health() -> dict:
    return {"status": "ok", "service": "maris-core-python"}


@app.get("/ready")
async def ready() -> JSONResponse:
    text_model = get_text_model_readiness(start_loading=True)
    payload = {
        "status": "ok" if text_model["ready"] else "not_ready",
        "service": "maris-core-python",
        "ready": text_model["ready"],
        "text_model": text_model,
    }
    return JSONResponse(status_code=200 if text_model["ready"] else 503, content=payload)


if __name__ == "__main__":
    uvicorn.run(
        "maris_core.__main__:app",
        host=resolve_host(),
        port=resolve_port(),
        reload=is_reload_enabled(),
    )