feat: initial commit

This commit is contained in:
Rodrigo Verdiani 2025-10-21 13:17:27 -03:00
commit 668c458a64
3 changed files with 64 additions and 0 deletions

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM python:3.13.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py .
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

47
app.py Normal file
View File

@ -0,0 +1,47 @@
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional
from rapidfuzz import fuzz
app = FastAPI()
# Request body schema
class MatchRequest(BaseModel):
title: str
options: List[str]
threshold: Optional[int] = 85 # default match threshold
# Response schema
class MatchResponse(BaseModel):
match_found: bool
best_match: Optional[str] = None
similarity: Optional[float] = None
@app.post("/match-title", response_model=MatchResponse)
def match_title(request: MatchRequest):
title = request.title
options = request.options
threshold = request.threshold
print(title)
print(options)
if not title or not options:
raise HTTPException(status_code=400, detail="Title and options are required.")
best_match = None
best_score = 0
for option in options:
score = fuzz.ratio(title, option)
if score > best_score:
best_score = score
best_match = option
if best_score >= threshold:
return MatchResponse(match_found=True, best_match=best_match, similarity=best_score)
else:
return MatchResponse(match_found=False)

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
fastapi~=0.119.0
pydantic~=2.12.3
RapidFuzz~=3.14.1
uvicorn