Vishalakak commited on
Commit
3b39ea1
·
1 Parent(s): f43d4e8

Initial Docker deployment of Flask app

Browse files
Files changed (7) hide show
  1. app.py +66 -0
  2. dockerfile +11 -0
  3. index.html +127 -0
  4. model.pkl +3 -0
  5. requirements.txt +6 -0
  6. scaler.pkl +3 -0
  7. templates/index.html +126 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ import pickle
3
+ import numpy as np
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Load model and scaler
8
+ with open("model.pkl", "rb") as f1:
9
+ model = pickle.load(f1)
10
+
11
+ with open("scaler.pkl", "rb") as f2:
12
+ scaler = pickle.load(f2)
13
+
14
+ FEATURES = [
15
+ 'Operation_Mode', 'Temperature_C', 'Vibration_Hz',
16
+ 'Power_Consumption_kW', 'Network_Latency_ms', 'Packet_Loss_%',
17
+ 'Quality_Control_Defect_Rate_%', 'Production_Speed_units_per_hr',
18
+ 'Predictive_Maintenance_Score', 'Error_Rate_%','Year', 'Month', 'Day', 'Hour'
19
+ ]
20
+
21
+ LABELS = {
22
+ 0:"High",
23
+ 1:"Low",
24
+ 2:"Medium"
25
+ }
26
+ # Dictionary of placeholders for each feature
27
+ placeholders = {
28
+ 'Operation_Mode': 'low-1,med-2,high-3',
29
+ 'Temperature_C': 'Enter the temprature',
30
+ 'Vibration_Hz': 'Enter in range(0.1-5)',
31
+ 'Power_Consumption_kW': 'Enter in range(1-10)',
32
+ 'Network_Latency_ms': 'Enter in range(1-50)',
33
+ 'Packet_Loss_%': 'e.g., 0.5....to 5',
34
+ 'Quality_Control_Defect_Rate_%': 'Enter in range(1-10)',
35
+ 'Production_Speed_units_per_hr': 'e.g., 1000',
36
+ 'Predictive_Maintenance_Score': 'e.g., 85',
37
+ 'Error_Rate_%': 'e.g., 1.2',
38
+ 'Year': 'e.g., 2025',
39
+ 'Month': 'e.g., 6',
40
+ 'Day': 'e.g., 27',
41
+ 'Hour': 'e.g., 14'
42
+ }
43
+
44
+
45
+ @app.route("/" , methods=["GET" , "POST"])
46
+ def index():
47
+ prediction = None
48
+
49
+ if request.method=="POST":
50
+ try:
51
+ input_data = [float(request.form[feature]) for feature in FEATURES]
52
+ input_array = np.array(input_data).reshape(1,-1)
53
+
54
+ scaled_array = scaler.transform(input_array)
55
+
56
+ pred = model.predict(scaled_array)[0]
57
+ prediction = LABELS.get(pred , "Unknown")
58
+
59
+ except Exception as e:
60
+ prediction = f"Error : {e}"
61
+
62
+ return render_template('index.html', features=FEATURES, placeholders=placeholders, prediction=prediction)
63
+
64
+
65
+ if __name__=="__main__":
66
+ app.run(debug=True , host="0.0.0.0" , port=7860)
dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . /app
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ EXPOSE 7860
10
+
11
+ CMD ["python", "app.py"]
index.html ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width , initial-scale=1.0">
6
+ <title>Smart Manufacturing Machines Efficiency Prediction</title>
7
+
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background-color:rgb(201, 224, 240);
12
+ background-image: url('https://www.shutterstock.com/shutterstock/photos/2235931143/display_1500/stock-photo-big-data-technology-and-data-science-data-scientist-querying-analysing-and-visualizing-complex-2235931143.jpg');
13
+ margin: 0;
14
+ height: 100vh;
15
+ background-size: cover;
16
+ animation: scrollBackground 30s linear infinite;
17
+ padding: 20px;
18
+ color: #333;
19
+ }
20
+ @keyframes scrollBackground {
21
+ 0% {
22
+ background-position: 0 0;
23
+ }
24
+ 100% {
25
+ background-position: -1000px 0;
26
+             }
27
+ }
28
+ h1 {
29
+ text-align: center;
30
+ color:rgb(214, 210, 210);
31
+ }
32
+
33
+ .form-container {
34
+ max-width: 900px;
35
+ margin: 0 auto;
36
+ background-color: #fff;
37
+ padding: 25px 30px;
38
+ border-radius: 10px;
39
+ box-shadow: 0 4px 12px rgba(133, 56, 56, 0.1);
40
+ }
41
+
42
+ .form-grid {
43
+ display: grid;
44
+ grid-template-columns: repeat(2, 1fr); /* 2 columns */
45
+ gap: 20px;
46
+ }
47
+
48
+ .form-group {
49
+ display: flex;
50
+ flex-direction: column;
51
+ }
52
+
53
+ label {
54
+ margin-bottom: 6px;
55
+ font-weight: bold;
56
+ color: #34495e;
57
+ }
58
+
59
+ input[type="text"] {
60
+ padding: 10px;
61
+ border: 1px solid #ccc;
62
+ border-radius: 6px;
63
+ transition: border-color 0.3s;
64
+ }
65
+
66
+ input[type="text"]:focus {
67
+ border-color: #3498db;
68
+ outline: none;
69
+ }
70
+
71
+ .submit-btn {
72
+ display: block;
73
+ margin: 30px auto 0 auto;
74
+ padding: 12px 30px;
75
+ background-color: #3498db;
76
+ color: #fff;
77
+ font-size: 16px;
78
+ font-weight: bold;
79
+ border: none;
80
+ border-radius: 8px;
81
+ cursor: pointer;
82
+ transition: background-color 0.3s;
83
+ }
84
+
85
+ .submit-btn:hover {
86
+ background-color: #2980b9;
87
+ }
88
+
89
+ h2 {
90
+ text-align: center;
91
+ margin-top: 25px;
92
+ color: #27ae60;
93
+ }
94
+
95
+ @media (max-width: 768px) {
96
+ .form-grid {
97
+ grid-template-columns: 1fr;
98
+ }
99
+ }
100
+ </style>
101
+ </head>
102
+
103
+ <body>
104
+ <h1>Smart Manufacturing Machines Efficiency Prediction</h1>
105
+
106
+ <form method="post" class="form-container">
107
+ <div class="form-grid">
108
+ {% for feature in features %}
109
+ <div class="form-group">
110
+ <label for="{{ feature }}">{{ feature }}:</label>
111
+ <input type="text" name="{{ feature }}" placeholder="{{ placeholders[feature] }}" required>
112
+
113
+ </div>
114
+ {% endfor %}
115
+ </div>
116
+
117
+ <button type="submit" class="submit-btn">PREDICT</button>
118
+ </form>
119
+
120
+ {% if prediction %}
121
+ <h2>Prediction : {{ prediction }}</h2>
122
+ {% endif %}
123
+ </body>
124
+
125
+ </html>
126
+
127
+
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6cba78a4df5b685023c6298a9d2ca80261574522873ec052a4a700360a13c889
3
+ size 7638579
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ flask
2
+ scikit-learn
3
+ numpy
4
+ pandas
5
+ joblib
6
+ gunicorn
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1eba3691125ff3032d9afaacca6132115b8bc70030d919b9e6da4eaf90565ef6
3
+ size 1122
templates/index.html ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width , initial-scale=1.0">
6
+ <title>Smart Manufacturing Machines Efficiency Prediction</title>
7
+
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background-color:rgb(201, 224, 240);
12
+ background-image: url('https://www.shutterstock.com/shutterstock/photos/2235931143/display_1500/stock-photo-big-data-technology-and-data-science-data-scientist-querying-analysing-and-visualizing-complex-2235931143.jpg');
13
+ margin: 0;
14
+ height: 100vh;
15
+ background-size: cover;
16
+ animation: scrollBackground 30s linear infinite;
17
+ padding: 20px;
18
+ color: #333;
19
+ }
20
+ @keyframes scrollBackground {
21
+ 0% {
22
+ background-position: 0 0;
23
+ }
24
+ 100% {
25
+ background-position: -1000px 0;
26
+             }
27
+ }
28
+ h1 {
29
+ text-align: center;
30
+ color:rgb(214, 210, 210);
31
+ }
32
+
33
+ .form-container {
34
+ max-width: 900px;
35
+ margin: 0 auto;
36
+ background-color: #fff;
37
+ padding: 25px 30px;
38
+ border-radius: 10px;
39
+ box-shadow: 0 4px 12px rgba(133, 56, 56, 0.1);
40
+ }
41
+
42
+ .form-grid {
43
+ display: grid;
44
+ grid-template-columns: repeat(2, 1fr); /* 2 columns */
45
+ gap: 20px;
46
+ }
47
+
48
+ .form-group {
49
+ display: flex;
50
+ flex-direction: column;
51
+ }
52
+
53
+ label {
54
+ margin-bottom: 6px;
55
+ font-weight: bold;
56
+ color: #34495e;
57
+ }
58
+
59
+ input[type="text"] {
60
+ padding: 10px;
61
+ border: 1px solid #ccc;
62
+ border-radius: 6px;
63
+ transition: border-color 0.3s;
64
+ }
65
+
66
+ input[type="text"]:focus {
67
+ border-color: #3498db;
68
+ outline: none;
69
+ }
70
+
71
+ .submit-btn {
72
+ display: block;
73
+ margin: 30px auto 0 auto;
74
+ padding: 12px 30px;
75
+ background-color: #3498db;
76
+ color: #fff;
77
+ font-size: 16px;
78
+ font-weight: bold;
79
+ border: none;
80
+ border-radius: 8px;
81
+ cursor: pointer;
82
+ transition: background-color 0.3s;
83
+ }
84
+
85
+ .submit-btn:hover {
86
+ background-color: #2980b9;
87
+ }
88
+
89
+ h2 {
90
+ text-align: center;
91
+ margin-top: 25px;
92
+ color: #27ae60;
93
+ }
94
+
95
+ @media (max-width: 768px) {
96
+ .form-grid {
97
+ grid-template-columns: 1fr;
98
+ }
99
+ }
100
+ </style>
101
+ </head>
102
+
103
+ <body>
104
+ <h1>Smart Manufacturing Machines Efficiency Prediction</h1>
105
+
106
+ <form method="post" class="form-container">
107
+ <div class="form-grid">
108
+ {% for feature in features %}
109
+ <div class="form-group">
110
+ <label for="{{ feature }}">{{ feature }}:</label>
111
+ <input type="text" name="{{ feature }}" placeholder="{{ placeholders[feature] }}" required>
112
+
113
+ </div>
114
+ {% endfor %}
115
+ </div>
116
+
117
+ <button type="submit" class="submit-btn">PREDICT</button>
118
+ </form>
119
+
120
+ {% if prediction %}
121
+ <h2>Prediction : {{ prediction }}</h2>
122
+ {% endif %}
123
+ </body>
124
+
125
+ </html>
126
+