feat: initial commit
This commit is contained in:
commit
668c458a64
13
Dockerfile
Normal file
13
Dockerfile
Normal 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
47
app.py
Normal 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
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
fastapi~=0.119.0
|
||||
pydantic~=2.12.3
|
||||
RapidFuzz~=3.14.1
|
||||
uvicorn
|
||||
Loading…
x
Reference in New Issue
Block a user