Spaces:
Sleeping
Sleeping
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', | |
} | |
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) |