Skip to content

Commit

Permalink
submit
Browse files Browse the repository at this point in the history
  • Loading branch information
metinkeremurkmez committed Jul 29, 2022
0 parents commit f47b2ed
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
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"]
15 changes: 15 additions & 0 deletions Pipfile
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"
241 changes: 241 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions README.md
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 added model_iLab_case.pkl
Binary file not shown.
Binary file added reco/__pycache__/api.cpython-39.pyc
Binary file not shown.
Binary file added reco/__pycache__/model.cpython-39.pyc
Binary file not shown.
35 changes: 35 additions & 0 deletions reco/api.py
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
"""
21 changes: 21 additions & 0 deletions reco/model.py
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

0 comments on commit f47b2ed

Please sign in to comment.