import os from fastapi import FastAPI from pydantic import BaseModel from typing import Optional from code.rag_core import RAGConfig, SongIndex, Responder, classify_title CSV_PATH = os.environ.get("CSV_PATH", "data.songs.csv") GENRE_NAME = os.environ.get("GENRE_NAME", "Rock & Roll") HF_HOME = os.environ.get("HF_HOME", "") app = FastAPI(title="RAG Rock & Roll Checker API", version="1.0.0") # Cargar índice al arrancar cfg = RAGConfig(songs_csv=CSV_PATH,cache = HF_HOME, genre_name=GENRE_NAME) song_index = SongIndex(cfg) responder = Responder(cfg.genre_name) class CheckRequest(BaseModel): title: str @app.get("/health") def health(): return {"status": "ok", "genre": cfg.genre_name, "count": len(song_index.df)} @app.post("/check") def check(req: CheckRequest): return classify_title(song_index, responder, req.title) @app.get("/") def root(): return { "hello": "RAG Rock & Roll", "docs": "/docs", "genre": cfg.genre_name, "usage": { "POST /check": {"title": "Jailhouse Rock"} } }