Skip to content

Commit

Permalink
Merge pull request #2 from arvinsingh/microservices
Browse files Browse the repository at this point in the history
Microservices
  • Loading branch information
arvinsingh authored Nov 9, 2024
2 parents aa54611 + 91056ed commit 7649c50
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 41 deletions.
33 changes: 33 additions & 0 deletions .github/actions/build-application/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: Build application
description: This action builds the application

runs:

using: 'composite'

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true # for caching dependencies

- name: Load cached virtualenv
uses: actions/cache@v2
id: cache-poetry-dependencies
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies using Poetry
if: steps.cache-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry run make install
shell: bash
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

name: Lint workflow

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build application
uses: ./.github/actions/build-application

- name: Lint with Flake8
run: poetry run make check
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.PHONY: run install check clean runner
.DEFAULT_GOAL := runner
.PHONY: run-builder run-inference install check clean runner-builder runner-inference
.DEFAULT_GOAL := runner-inference

run: install
cd src; poetry run python runner.py;
run-builder: install
cd src; poetry run python runner_builder.py;

run-inference: install
cd src; poetry run python runner_inference.py;

install:
poetry install
Expand All @@ -13,4 +16,6 @@ check:
clean:
rm -rf `find . -type d -name __pycache__`

runner: check run clean
runner-builder: check run-builder clean

runner-inference: check run-inference clean
18 changes: 18 additions & 0 deletions src/model/model_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from loguru import logger

from config import model_settings
from model.pipeline.model import build_model


class ModelBuilderService:

def __init__(self):
self.model_path = model_settings.model_path
self.model_name = model_settings.model_name

def load_model(self):
logger.info(
f'Building the model file at '
f'{self.model_path}/{self.model_name}',
)
build_model()
36 changes: 36 additions & 0 deletions src/model/model_inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path
import pickle as pkl

from loguru import logger

from config import model_settings


class ModelInferenceService:

def __init__(self):
self.model = None
self.model_path = model_settings.model_path
self.model_name = model_settings.model_name

def load_model(self):
logger.info(
f'Checking for existing model file at '
f'{self.model_path}/{self.model_name}',
)
model_path = Path(
f'{self.model_path}/{self.model_name}',
)

if not model_path.exists():
raise FileNotFoundError(
f'Model file {self.model_name} does not exist!',
)

logger.info(f'Loading existing model -> {model_path}')
with open(model_path, 'rb') as model_file:
self.model = pkl.load(model_file)

def predict(self, input_parameters):
logger.info('Making predictions')
return self.model.predict([input_parameters])
36 changes: 0 additions & 36 deletions src/model/model_service.py

This file was deleted.

14 changes: 14 additions & 0 deletions src/runner_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from loguru import logger

from model.model_builder import ModelBuilderService


@logger.catch
def main():
logger.info('Running builder application')
ml_svc = ModelBuilderService()
ml_svc.train_model()


if __name__ == '__main__':
main()
File renamed without changes.

0 comments on commit 7649c50

Please sign in to comment.