Spaces:
Running
Running
Commit ·
617515c
1
Parent(s): e712ea6
Add remaining changes to previous commit
Browse files- .gitignore +4 -1
- config.py +3 -1
- src/api/main.py +14 -4
.gitignore
CHANGED
|
@@ -3,4 +3,7 @@ __pycache__
|
|
| 3 |
.env
|
| 4 |
data
|
| 5 |
.gradio
|
| 6 |
-
supabase_dump.sql
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
.env
|
| 4 |
data
|
| 5 |
.gradio
|
| 6 |
+
supabase_dump.sql
|
| 7 |
+
src/ui/node_modules/
|
| 8 |
+
src/ui/.next/
|
| 9 |
+
src/ui/.env.local
|
config.py
CHANGED
|
@@ -8,9 +8,11 @@ class Settings(BaseSettings):
|
|
| 8 |
postgres_user: str
|
| 9 |
postgres_password: str
|
| 10 |
postgres_db: str
|
| 11 |
-
database_url: str
|
| 12 |
qdrant_url: str
|
| 13 |
qdrant_api_key: str
|
|
|
|
|
|
|
| 14 |
|
| 15 |
class Config:
|
| 16 |
env_file = '.env'
|
|
|
|
| 8 |
postgres_user: str
|
| 9 |
postgres_password: str
|
| 10 |
postgres_db: str
|
| 11 |
+
database_url: str
|
| 12 |
qdrant_url: str
|
| 13 |
qdrant_api_key: str
|
| 14 |
+
fastapi_api_key: str
|
| 15 |
+
frontend_api_key: str
|
| 16 |
|
| 17 |
class Config:
|
| 18 |
env_file = '.env'
|
src/api/main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from src.retrieval.rag_pipeline import AnimeRAGPipeline
|
| 2 |
-
from fastapi import FastAPI, HTTPException, status, Request
|
|
|
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
from pydantic import BaseModel, Field
|
| 5 |
import uvicorn
|
|
@@ -13,6 +14,15 @@ from contextlib import asynccontextmanager
|
|
| 13 |
logger = logging.basicConfig(level=logging.INFO)
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@asynccontextmanager
|
| 18 |
async def lifespan(app: FastAPI):
|
|
@@ -53,7 +63,7 @@ async def root():
|
|
| 53 |
|
| 54 |
|
| 55 |
@app.post("/recommend", response_model=RecommendationResponse)
|
| 56 |
-
async def get_recommendations(request: RecommendationRequest, fastapi_req: Request):
|
| 57 |
"""
|
| 58 |
Get anime recommendation based on user query
|
| 59 |
|
|
@@ -112,12 +122,12 @@ async def get_recommendations(request: RecommendationRequest, fastapi_req: Reque
|
|
| 112 |
|
| 113 |
|
| 114 |
@app.get("/stats")
|
| 115 |
-
async def get_stats(fastapi_req: Request):
|
| 116 |
"""Get system statistics"""
|
| 117 |
rag_pipeline = fastapi_req.app.state.pipeline
|
| 118 |
|
| 119 |
return {
|
| 120 |
-
"total_anime": rag_pipeline.retriever.
|
| 121 |
"embedding_model": "all-MiniLM-L6-v2",
|
| 122 |
"llm_model": settings.model_name,
|
| 123 |
"retrieval_k": rag_pipeline.retriever_k
|
|
|
|
| 1 |
from src.retrieval.rag_pipeline import AnimeRAGPipeline
|
| 2 |
+
from fastapi import FastAPI, HTTPException, status, Request, Security, Depends
|
| 3 |
+
from fastapi.security import APIKeyHeader
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from pydantic import BaseModel, Field
|
| 6 |
import uvicorn
|
|
|
|
| 14 |
logger = logging.basicConfig(level=logging.INFO)
|
| 15 |
logger = logging.getLogger(__name__)
|
| 16 |
|
| 17 |
+
api_key_header = APIKeyHeader(name="X-API-Key")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
async def verify_api_key(api_key: str = Security(api_key_header)):
|
| 21 |
+
if api_key != settings.fastapi_api_key:
|
| 22 |
+
raise HTTPException(
|
| 23 |
+
status_code=status.HTTP_403_FORBIDDEN, detail="Invalid API Key")
|
| 24 |
+
return api_key
|
| 25 |
+
|
| 26 |
|
| 27 |
@asynccontextmanager
|
| 28 |
async def lifespan(app: FastAPI):
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
@app.post("/recommend", response_model=RecommendationResponse)
|
| 66 |
+
async def get_recommendations(request: RecommendationRequest, fastapi_req: Request, _=Depends(verify_api_key)):
|
| 67 |
"""
|
| 68 |
Get anime recommendation based on user query
|
| 69 |
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
@app.get("/stats")
|
| 125 |
+
async def get_stats(fastapi_req: Request, _=Depends(verify_api_key)):
|
| 126 |
"""Get system statistics"""
|
| 127 |
rag_pipeline = fastapi_req.app.state.pipeline
|
| 128 |
|
| 129 |
return {
|
| 130 |
+
"total_anime": rag_pipeline.retriever.points_count,
|
| 131 |
"embedding_model": "all-MiniLM-L6-v2",
|
| 132 |
"llm_model": settings.model_name,
|
| 133 |
"retrieval_k": rag_pipeline.retriever_k
|