Skip to content

Commit

Permalink
🚑 little hotfix with windows
Browse files Browse the repository at this point in the history
little hotfix with windows
  • Loading branch information
ekzm8523 committed Oct 6, 2022
1 parent b27442b commit c983b33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import typing
from typing import Literal
import platform

import boto3
from dotenv import load_dotenv
Expand Down Expand Up @@ -43,3 +44,5 @@ def get_secret():
KEYWORD_MODEL_S3_PATH = os.getenv("KEYWORD_MODEL_S3_PATH")
CONTENT_MODEL_S3_PATH = os.getenv("CONTENT_MODEL_S3_PATH")
STOPWORD_FILE_PATH = "app/static/stopwords.txt"
OS = platform.system()
MECAB_DIC_PATH = "C:\mecab/mecab-ko-dic"
8 changes: 7 additions & 1 deletion app/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
Problem,
)
from app.utils.utils import get_stopwords
from app.config import OS, MECAB_DIC_PATH

log = logging.getLogger("__main__")


if OS == "Windows":
import win32file
win32file._setmaxstdio(2048)


class KeywordPredictRunnable(bentoml.Runnable):
SUPPORTS_CPU_MULTI_THREADING = True
threshold = 0.5
Expand All @@ -37,7 +43,7 @@ def __init__(self, problem_dict: Optional[dict] = None):
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
log.info(f"keyword predict model is running on {self.device}")
self.model = get_keyword_grading_model().to(self.device)
self.tokenizer = Mecab()
self.tokenizer = Mecab(MECAB_DIC_PATH) if OS == "Windows" else Mecab()
self.stopwords = get_stopwords()

def create_problem(self, input_data: KeywordGradingRequest) -> None:
Expand Down
2 changes: 1 addition & 1 deletion app/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@


def get_stopwords() -> Set:
return set(Path(STOPWORD_FILE_PATH).read_text().split("\n"))
return set(Path(STOPWORD_FILE_PATH).read_text(encoding="UTF-8").split("\n"))

0 comments on commit c983b33

Please sign in to comment.