Skip to content

Commit

Permalink
refact: alterando arquivo pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
heltonricardo committed Dec 13, 2023
1 parent f2c44a3 commit b1acb78
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 27 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Train-Pipeline
name: Train Pipeline

on:
push:
Expand All @@ -13,6 +13,7 @@ on:
- webhook
jobs:
test_train:
name: Test train
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -30,31 +31,31 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test files
run: pytest test_train.py

check_python_code_style:
name: Check Python code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install dependencies
run: |
pytest test_train.py
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# check_python_code_style:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# with:
# fetch-depth: 0
#
# - name: Set up Python 3.9
# uses: actions/setup-python@v1
# with:
# python-version: 3.9
#
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
#
# - name: Validate Python Code Style
# run: |
# pycodestyle .
- name: Validate Python Code Style
run: pycodestyle .

train_pipeline:
name: Train pipeline
runs-on: ubuntu-latest
needs: [test_train]
steps:
Expand All @@ -73,17 +74,16 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Train Model
run: |
python train.py
run: python train.py

build_image:
name: Build image
runs-on: ubuntu-latest
needs: [train_pipeline]
steps:
- uses: actions/checkout@v2
- name: docker login
run: |
docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASSWORD}}
- name: Docker Login
run: docker login -u ${{secrets.DOCKER_USER}} -p ${{secrets.DOCKER_PASSWORD}}
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/${{secrets.DOCKER_IMAGE_NAME}}

Expand Down
259 changes: 259 additions & 0 deletions model_registry.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"## Instalando o MLflow"
],
"metadata": {
"id": "cL8iUNRkKnnN"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8ZqLomD1JbEn"
},
"outputs": [],
"source": [
"!pip install mlflow==2.2.2 -q"
]
},
{
"cell_type": "markdown",
"source": [
"## import das bibliotecas"
],
"metadata": {
"id": "jAnzWtfqKsfI"
}
},
{
"cell_type": "code",
"source": [
"import os\n",
"import mlflow\n",
"import numpy as np"
],
"metadata": {
"id": "MAn3URFmJihs"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Configurando o MLflow"
],
"metadata": {
"id": "PhBP5HFCKvYb"
}
},
{
"cell_type": "code",
"source": [
"MLFLOW_TRACKING_URI = ''\n",
"MLFLOW_TRACKING_USERNAME = ''\n",
"MLFLOW_TRACKING_PASSWORD = ''\n",
"os.environ['MLFLOW_TRACKING_USERNAME'] = MLFLOW_TRACKING_USERNAME\n",
"os.environ['MLFLOW_TRACKING_PASSWORD'] = MLFLOW_TRACKING_PASSWORD\n",
"\n",
"mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)"
],
"metadata": {
"id": "Bu43IC6oJj1L"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Criando um client para comunicar com o registro no DagsHub"
],
"metadata": {
"id": "dbFFAEaGK0lX"
}
},
{
"cell_type": "code",
"source": [
"client = mlflow.MlflowClient(tracking_uri=MLFLOW_TRACKING_URI)"
],
"metadata": {
"id": "wax9ipKjKShr"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"client"
],
"metadata": {
"id": "fWlu0lRiLp3u"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Recebendo o modelo registrado e suas versões"
],
"metadata": {
"id": "m1NMo6kfLBtq"
}
},
{
"cell_type": "code",
"source": [
"registered_model = client.get_registered_model('MODEL_NAME')"
],
"metadata": {
"id": "8oSsyfv0K6j5"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"registered_model.latest_versions"
],
"metadata": {
"id": "e2DDK_6_LPi5"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Obtendo o id da execução do modelo"
],
"metadata": {
"id": "DfBd2wRdLRPC"
}
},
{
"cell_type": "code",
"source": [
"run_id = registered_model.latest_versions[-1].run_id"
],
"metadata": {
"id": "HG-BzNlkK9oC"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Carregando o modelo"
],
"metadata": {
"id": "WORhnvgnLYrX"
}
},
{
"cell_type": "code",
"source": [
"logged_model = f'runs:/{run_id}/model'\n",
"loaded_model = mlflow.pyfunc.load_model(logged_model)"
],
"metadata": {
"id": "xa1ZTR6OK_hg"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Fazendo uma predição com o modelo carregadO"
],
"metadata": {
"id": "IQBbf3xULc1A"
}
},
{
"cell_type": "code",
"source": [
"accelerations = 0\n",
"fetal_movement = 0\n",
"uterine_contractions = 0\n",
"severe_decelerations = 0"
],
"metadata": {
"id": "SwbDW9aLJziQ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"received_data = np.array([\n",
" accelerations,\n",
" fetal_movement,\n",
" uterine_contractions,\n",
" severe_decelerations,\n",
" ]).reshape(1, -1)"
],
"metadata": {
"id": "s-Ed15fsJv5k"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"received_data"
],
"metadata": {
"id": "Mpc1_Y57J_xV"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"loaded_model.predict(received_data)"
],
"metadata": {
"id": "lV6gcA8dJmX0"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "k3qYyLsyKDVb"
},
"execution_count": null,
"outputs": []
}
]
}

0 comments on commit b1acb78

Please sign in to comment.