Spaces:
Sleeping
Sleeping
File size: 1,607 Bytes
44ed2c7 9a01e3a 44ed2c7 18292ea | 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 | import os
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from app.api.routes import router
app = FastAPI(
title="RAG Chatbot API",
description="RESTful API cho hệ thống Multimodal RAG Chatbot",
version="1.0.0"
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
import threading
@app.on_event("startup")
def preload_models():
def load():
try:
print("Đang tải trước mô hình Embeddings...")
from app.core.config import get_embeddings
get_embeddings()
print("Đang tải trước mô hình Rerank...")
from app.service.retriever import get_rerank_model
get_rerank_model()
print("Tải mô hình hoàn tất.")
except Exception as e:
print(f"Lỗi khi tải trước mô hình: {e}")
threading.Thread(target=load, daemon=True).start()
app.include_router(router, prefix="/api/v1")
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/", summary="Giao diện Web Chatbot")
async def serve_frontend():
return FileResponse("static/index.html")
if __name__ == "__main__":
os.makedirs("./data", exist_ok=True)
port = int(os.getenv("PORT", 8000))
print(f"Khởi động server API tại http://localhost:{port}")
uvicorn.run("api:app", host="0.0.0.0", port=port, reload=True)
|