Skip to content

Commit

Permalink
prediction and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamgore2468 committed Aug 15, 2024
1 parent e9cbe55 commit a8ab623
Show file tree
Hide file tree
Showing 16 changed files with 12,182 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Empty file removed .github/workflows/.gitkeep
Empty file.
96 changes: 96 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: workflow

on:
push:
branches:
- main
paths-ignore:
- "README.md"

permissions:
id-token: write
contents: read

jobs:
integration:
name: Continuous Integration
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Lint code
run: echo "Linting repository"

- name: Run unit tests
run: echo "Running unit tests"

build-and-push-ecr-image:
name: Continuous Delivery
needs: integration
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Utilities
run: |
sudo apt-get update
sudo apt-get install -y jq unzip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
IMAGE_TAG: latest
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
Continuous-Deployment:
needs: build-and-push-ecr-image
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Pull latest images
run: |
docker pull ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
# - name: Stop and remove container if running
# run: |
# docker ps -q --filter "name=mlproj" | grep -q . && docker stop mlproj && docker rm -fv mlproj

- name: Run Docker Image to serve users
run: |
docker run -d -p 8080:8080 --name=mlproj -e 'AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}' -e 'AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}' -e 'AWS_REGION=${{ secrets.AWS_REGION }}' ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
- name: Clean previous images and containers
run: |
docker system prune -f
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8-slim-buster

RUN apt update -y && apt install awscli -y
WORKDIR /app

COPY . /app
RUN pip install -r requirements.txt

CMD ["python3", "app.py"]
53 changes: 53 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from flask import Flask, render_template, request
import os
import numpy as np
import pandas as pd
from src.mlProject.pipeline.prediction import PredictionPipeline

app = Flask(__name__)

@app.route('/', methods=['GET'])
def homePage():
return render_template("index.html")

@app.route('/train', methods=['GET'])
def training():
os.system("python main.py")
return "Training Successful"

@app.route('/predict',methods=['POST','GET']) # route to show the predictions in a web UI
def index():
if request.method == 'POST':
try:
# reading the inputs given by the user
fixed_acidity =float(request.form['fixed_acidity'])
volatile_acidity =float(request.form['volatile_acidity'])
citric_acid =float(request.form['citric_acid'])
residual_sugar =float(request.form['residual_sugar'])
chlorides =float(request.form['chlorides'])
free_sulfur_dioxide =float(request.form['free_sulfur_dioxide'])
total_sulfur_dioxide =float(request.form['total_sulfur_dioxide'])
density =float(request.form['density'])
pH =float(request.form['pH'])
sulphates =float(request.form['sulphates'])
alcohol =float(request.form['alcohol'])


data = [fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,pH,sulphates,alcohol]
data = np.array(data).reshape(1, 11)

obj = PredictionPipeline()
predict = obj.predict(data)

return render_template('results.html', prediction = str(predict))

except Exception as e:
print('The Exception message is: ',e)
return 'something is wrong'

else:
return render_template('index.html')


if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
46 changes: 46 additions & 0 deletions logs/running_logs.log
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,49 @@ x==========x]
[2024-08-14 18:26:59,063: INFO: common: created directory at: artifacts/model_evaluation]
[2024-08-14 18:26:59,786: INFO: common: json file saved at: artifacts/model_evaluation/metrics.json]
[2024-08-14 18:27:06,206: INFO: main: Completed Model Evaluation Stage]
[2024-08-14 18:51:21,242: INFO: _internal: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:8080
* Running on http://192.168.1.145:8080]
[2024-08-14 18:51:21,242: INFO: _internal: Press CTRL+C to quit]
[2024-08-14 18:51:21,242: INFO: _internal: * Restarting with stat]
[2024-08-14 18:51:21,721: WARNING: _internal: * Debugger is active!]
[2024-08-14 18:51:21,731: INFO: _internal: * Debugger PIN: 389-252-337]
[2024-08-14 18:51:39,305: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET / HTTP/1.1" 200 -]
[2024-08-14 18:51:39,438: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET /static/css/styles.css HTTP/1.1" 404 -]
[2024-08-14 18:51:39,439: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET /static/css2/nunito-font.css HTTP/1.1" 404 -]
[2024-08-14 18:51:39,440: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET /static/css2/style.css HTTP/1.1" 404 -]
[2024-08-14 18:51:39,441: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET /static/js/scripts.js HTTP/1.1" 404 -]
[2024-08-14 18:51:39,819: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET /static/assets/img/wine.jpg HTTP/1.1" 404 -]
[2024-08-14 18:51:39,819: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:39] "GET /static/assets/img/form-v9.jpg HTTP/1.1" 404 -]
[2024-08-14 18:51:40,624: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:51:40] "GET /static/assets/favicon.ico HTTP/1.1" 404 -]
[2024-08-14 18:52:59,451: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET / HTTP/1.1" 200 -]
[2024-08-14 18:52:59,618: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/css/styles.css HTTP/1.1" 200 -]
[2024-08-14 18:52:59,621: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/js/scripts.js HTTP/1.1" 200 -]
[2024-08-14 18:52:59,622: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/css2/nunito-font.css HTTP/1.1" 200 -]
[2024-08-14 18:52:59,622: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/css2/style.css HTTP/1.1" 200 -]
[2024-08-14 18:52:59,650: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/assets/img/wine.jpg HTTP/1.1" 404 -]
[2024-08-14 18:52:59,654: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/assets/img/form-v9.jpg HTTP/1.1" 200 -]
[2024-08-14 18:52:59,786: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 18:52:59] "GET /static/fonts/Nunito/Nunito-Bold.ttf HTTP/1.1" 404 -]
[2024-08-14 18:54:43,275: INFO: _internal: * Detected change in '/Users/shubhamgore/Development/ML_Projects/MLOPS/app.py', reloading]
[2024-08-14 18:54:43,515: INFO: _internal: * Restarting with stat]
[2024-08-14 18:59:26,099: INFO: _internal: WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:8080
* Running on http://192.168.1.145:8080]
[2024-08-14 18:59:26,099: INFO: _internal: Press CTRL+C to quit]
[2024-08-14 18:59:26,100: INFO: _internal: * Restarting with stat]
[2024-08-14 18:59:26,622: WARNING: _internal: * Debugger is active!]
[2024-08-14 18:59:26,632: INFO: _internal: * Debugger PIN: 389-252-337]
[2024-08-14 19:00:54,674: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET / HTTP/1.1" 200 -]
[2024-08-14 19:00:54,833: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/css2/nunito-font.css HTTP/1.1" 304 -]
[2024-08-14 19:00:54,833: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/css2/style.css HTTP/1.1" 304 -]
[2024-08-14 19:00:54,834: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/js/scripts.js HTTP/1.1" 304 -]
[2024-08-14 19:00:54,835: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/css/styles.css HTTP/1.1" 304 -]
[2024-08-14 19:00:54,881: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/assets/img/wine.jpg HTTP/1.1" 404 -]
[2024-08-14 19:00:54,883: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/assets/img/form-v9.jpg HTTP/1.1" 304 -]
[2024-08-14 19:00:54,904: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:00:54] "GET /static/fonts/Nunito/Nunito-Bold.ttf HTTP/1.1" 404 -]
[2024-08-14 19:01:19,043: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:01:19] "POST /predict HTTP/1.1" 200 -]
[2024-08-14 19:01:19,187: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:01:19] "GET /static/css/styles.css HTTP/1.1" 304 -]
[2024-08-14 19:01:19,187: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:01:19] "GET /static/js/scripts.js HTTP/1.1" 304 -]
[2024-08-14 19:01:19,215: INFO: _internal: 127.0.0.1 - - [14/Aug/2024 19:01:19] "GET /static/assets/img/wine.gif HTTP/1.1" 404 -]
Binary file not shown.
13 changes: 13 additions & 0 deletions src/mlProject/pipeline/prediction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import joblib
import numpy as np
import pandas as pd
from pathlib import Path

class PredictionPipeline:
def __init__(self):
self.model = joblib.load(Path('artifacts/model_trainer/model.joblib'))

def predict(self, data):
prediction = self.model.predict(data)

return prediction
Binary file added static/assets/favicon.ico
Binary file not shown.
Binary file added static/assets/img/form-v9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a8ab623

Please sign in to comment.