Atlas3 / app.py
Vincelil's picture
DΓ©ploiement initial de ATLAS-3 Thinking via Manus
5ee6fe1 verified
Raw
History Blame Contribute Delete
3.04 kB
"""
╔══════════════════════════════════════════════════════════════════╗
β•‘ ATLAS-3 THINKING β€” Server A β•‘
β•‘ HuggingFace Space : Vincelil/Atlas3 β•‘
β•‘ FastAPI + ORO T3 (1000 unitΓ©s vectorisΓ©es) β•‘
β•‘ Interroge Vincelil/Atlasdata via streaming β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
"""
import asyncio
import time
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from oro_t3 import OroT3Engine
from faiss_index import FaissIndexer
# ── DΓ©marrage : construction de l'index en arriΓ¨re-plan ───────────
indexer = FaissIndexer()
engine = OroT3Engine(indexer)
@asynccontextmanager
async def lifespan(app: FastAPI):
# Lance l'indexation FAISS en tΓ’che de fond au dΓ©marrage
asyncio.create_task(indexer.build_async())
yield
indexer.stop()
app = FastAPI(
title="ATLAS-3 Thinking",
description="ORO T3 β€” 1000 unitΓ©s vectorisΓ©es sur FineWeb 15T",
lifespan=lifespan,
)
# ── ModΓ¨les Pydantic ──────────────────────────────────────────────
class QueryRequest(BaseModel):
query: str
top_k: int = 5
class QueryResponse(BaseModel):
query: str
output: str
oro_results: list
faiss_hits: list
index_size: int
tick: int
duration_ms: float
# ── Routes ────────────────────────────────────────────────────────
@app.get("/", response_class=HTMLResponse)
async def root():
with open("templates/index.html", encoding="utf-8") as f:
return f.read()
@app.post("/query", response_model=QueryResponse)
async def query(req: QueryRequest):
if not req.query.strip():
raise HTTPException(400, "Query vide")
t0 = time.perf_counter()
result = await engine.process(req.query, req.top_k)
result["duration_ms"] = round((time.perf_counter() - t0) * 1000, 2)
return JSONResponse(result)
@app.get("/status")
async def status():
return {
"index_size": indexer.size(),
"index_ready": indexer.is_ready(),
"index_pct": indexer.progress_pct(),
"oro_tick": engine.tick,
"oro_count": engine.n_oro,
"dataset": "Vincelil/Atlasdata",
}
@app.get("/oro/apprentissage")
async def apprentissage():
return engine.get_learning_state()