-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f47b2ed
Showing
9 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
FROM python:3.9 | ||
|
||
# | ||
WORKDIR /code | ||
|
||
# | ||
COPY ./Pipfile /code/Pipfile | ||
|
||
COPY ./model_iLab_case.pkl /code/model_iLab_case.pkl | ||
|
||
# | ||
RUN pip install pipenv | ||
RUN pipenv install | ||
|
||
# | ||
COPY ./reco /code/reco | ||
|
||
# | ||
CMD ["pipenv", "run", "uvicorn", "reco.api:app", "--host", "0.0.0.0", "--port", "80", "--reload"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
fastapi = "*" | ||
uvicorn = "*" | ||
pydantic = "*" | ||
gensim = "==3.8.3" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3.9" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# DOCKERIZED WORD2VEC RECOMMENDATION SYSTEM MODEL | ||
|
||
About Running: | ||
|
||
```sh | ||
sudo docker build -t test . | ||
``` | ||
```sh | ||
sudo docker run --net=host test | ||
``` | ||
|
||
POSTMAN; | ||
|
||
POST REQUEST URL : http://0.0.0.0:80/predict | ||
|
||
Example Request JSON Body; {"product_id" : "a368901216"} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from fastapi import FastAPI, Depends | ||
from pydantic import BaseModel | ||
from typing import List, Tuple | ||
|
||
from .model import get_model, Model | ||
|
||
app = FastAPI() | ||
|
||
|
||
class RecoRequest(BaseModel): | ||
product_id: str | ||
|
||
|
||
class RecoResponse(BaseModel): | ||
recos: List[List] | ||
# Senaryo2: RecoResponse class'i yoruma alinir. | ||
|
||
@app.post("/predict", response_model=RecoResponse) | ||
# Senaryo2: response_model = List[Tuple[str,float]] seklinde verilir. Return reco yapilir. | ||
def predict(request: RecoRequest, model: Model = Depends(get_model)): | ||
reco = model.predict(request.product_id) | ||
return RecoResponse( | ||
recos=reco | ||
) | ||
|
||
## DIGER CALISAN YOL ## | ||
|
||
""" | ||
class RecoResponse silinir. | ||
@app.post("/predict", response_model=List[Tuple[str,float]]) | ||
def predict(request: RecoRequest, model: Model = Depends(get_model)): | ||
reco = model.predict(request.product_id) | ||
return reco | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from gensim.models import Word2Vec | ||
import pickle | ||
|
||
|
||
class Model: | ||
def __init__(self): | ||
with open('model_iLab_case.pkl', 'rb') as f: | ||
model_loaded = pickle.load(f) | ||
|
||
self.model = model_loaded | ||
|
||
def predict(self, product_id): | ||
result = self.model.wv.most_similar(product_id, topn=15) | ||
return result | ||
|
||
|
||
model = Model() | ||
|
||
|
||
def get_model(): | ||
return model |