CoolFace
Apppublic

SUSAN27/Motor

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
app.py65 linesDownload Raw Back to root
1import pandas as pd2import numpy as np3from sklearn.model_selection import train_test_split4from sklearn.linear_model import LogisticRegression5from sklearn.metrics import accuracy_score6from sklearn.preprocessing import StandardScaler7 8 9motor_data=pd.read_csv('NEW1.csv',header=None)10motor_data.columns = ['Current','RPM','Temperature','Voltage', 'Status']11X=motor_data.drop('Status',axis=1)12Y=motor_data['Status']13 14X_train,X_test,y_train,y_test=train_test_split(X,Y,test_size=0.2,stratify=Y,random_state=2)15 16model = LogisticRegression(max_iter=10000)17model.fit(X_train, y_train)18 19 20import joblib21joblib.dump(model, 'model.pkl')22 23 24 25 26 27 28 29 30 31 32 33import gradio as gr34 35from fastapi import FastAPI36app = FastAPI()37model = joblib.load('model.pkl')38 39async def predict(current, rpm, temperature, voltage):40    # Convert the input data to the appropriate format for the model41    input_data = (current, rpm, temperature, voltage)42    input_data_as_numpy_array =np.asarray(input_data)43    input_data_reshaped=input_data_as_numpy_array.reshape(1,-1)44    input_df = pd.DataFrame(input_data_reshaped, columns=['Current','RPM','Temperature','Voltage'])45 46    prediction=model.predict(input_df)47    if prediction==1:48      return 149    else:50      return 051iface = gr.Interface(52    fn=predict,53    inputs=[54        gr.Number(label="Current"),55        gr.Number(label="RPM"),56        gr.Number(label="Temperature"),57        gr.Number(label="Voltage")58    ],59    outputs="text",60    title="Motor Maintenance Predictor"61)62 63# Launch the interface64iface.launch(inline = False)65