File size: 1,996 Bytes
3b39ea1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, render_template, request
import pickle
import numpy as np

app = Flask(__name__)

# Load model and scaler
with open("model.pkl", "rb") as f1:
    model = pickle.load(f1)

with open("scaler.pkl", "rb") as f2:
    scaler = pickle.load(f2)
    
FEATURES = [
                'Operation_Mode', 'Temperature_C', 'Vibration_Hz',
                'Power_Consumption_kW', 'Network_Latency_ms', 'Packet_Loss_%',
                'Quality_Control_Defect_Rate_%', 'Production_Speed_units_per_hr',
                'Predictive_Maintenance_Score', 'Error_Rate_%','Year', 'Month', 'Day', 'Hour'
            ]

LABELS = {
    0:"High",
    1:"Low",
    2:"Medium"
}
# Dictionary of placeholders for each feature
placeholders = {
    'Operation_Mode': 'low-1,med-2,high-3',
    'Temperature_C': 'Enter the temprature',
    'Vibration_Hz': 'Enter in range(0.1-5)',
    'Power_Consumption_kW': 'Enter in range(1-10)',
    'Network_Latency_ms': 'Enter in range(1-50)',
    'Packet_Loss_%': 'e.g., 0.5....to 5',
    'Quality_Control_Defect_Rate_%': 'Enter in range(1-10)',
    'Production_Speed_units_per_hr': 'e.g., 1000',
    'Predictive_Maintenance_Score': 'e.g., 85',
    'Error_Rate_%': 'e.g., 1.2',
    'Year': 'e.g., 2025',
    'Month': 'e.g., 6',
    'Day': 'e.g., 27',
    'Hour': 'e.g., 14'
}


@app.route("/" , methods=["GET" , "POST"])
def index():
    prediction = None

    if request.method=="POST":
        try:
            input_data = [float(request.form[feature]) for feature in FEATURES]
            input_array = np.array(input_data).reshape(1,-1)

            scaled_array = scaler.transform(input_array)

            pred = model.predict(scaled_array)[0]
            prediction = LABELS.get(pred , "Unknown")

        except Exception as e:
            prediction = f"Error : {e}"

    return render_template('index.html', features=FEATURES, placeholders=placeholders, prediction=prediction)


if __name__=="__main__":
    app.run(debug=True , host="0.0.0.0" , port=7860)