-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.py
27 lines (22 loc) · 799 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from fastapi import FastAPI
from pydantic import BaseModel
from sentence_transformers import SentenceTransformer
from utils.similarity import get_similar_items
import pandas as pd
import numpy as np
clothing_data = pd.read_csv('data/clothing_data_preprocessed.csv')
model = SentenceTransformer('model')
embeddings = np.load('data/embeddings.npy')
app = FastAPI()
class Query(BaseModel):
query: str
@app.post("/predict")
def getURL(query: Query):
# Get the query from the request payload
query_text = query.query
# Call your function to retrieve similar item URLs
similar_urls = get_similar_items(query_text, embeddings, clothing_data, 5)
return {"similar_urls": similar_urls}
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host='0.0.0.0', port=8080)