From 668c458a643d1e327138839684906bb6dedbab9b Mon Sep 17 00:00:00 2001 From: Rodrigo Verdiani Date: Tue, 21 Oct 2025 13:17:27 -0300 Subject: [PATCH] feat: initial commit --- Dockerfile | 13 +++++++++++++ app.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 3 files changed, 64 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..92d09e5 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..1131ed3 --- /dev/null +++ b/app.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c080a12 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +fastapi~=0.119.0 +pydantic~=2.12.3 +RapidFuzz~=3.14.1 +uvicorn \ No newline at end of file