Spaces:
Sleeping
Sleeping
File size: 1,924 Bytes
d24225f 412c43a d24225f 1f6a386 d24225f 1f6a386 d24225f |
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 |
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_%'
]
LABELS = {
0:"HIGH",
1:"LOW",
2:"MEDIUM"
}
# Dictionary of placeholders for each feature
placeholders = {
'Operation_Mode': 'Select Operation Mode',
'Temperature_C': 'Enter the temprature',
'Vibration_Hz': 'Enter the Vibration',
'Power_Consumption_kW': 'Enter the power consuption',
'Network_Latency_ms': 'Enter the network latency',
'Packet_Loss_%': 'Enter Packet Loss:',
'Quality_Control_Defect_Rate_%': 'Enter quality Defect Rate',
'Production_Speed_units_per_hr': 'Enter Production Unit',
'Predictive_Maintenance_Score': 'Enter Maintenance Score',
'Error_Rate_%': 'Enter Error Rate',
}
@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) |