Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -91,8 +91,7 @@ with st.form("engine_input_form"):
|
|
| 91 |
# Predict Button
|
| 92 |
# -----------------------------
|
| 93 |
if submit:
|
| 94 |
-
|
| 95 |
-
input_df = pd.DataFrame({
|
| 96 |
"engine_rpm": [engine_rpm],
|
| 97 |
"lub_oil_pressure": [lub_oil_pressure],
|
| 98 |
"fuel_pressure": [fuel_pressure],
|
|
@@ -101,46 +100,46 @@ if submit:
|
|
| 101 |
"coolant_temp": [coolant_temp]
|
| 102 |
})
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
| 115 |
label="Maintenance Needed"
|
| 116 |
st.warning(f"Engine needs Preventive maintenance. Probability: {prob:.2f}")
|
| 117 |
-
|
| 118 |
label="Normal"
|
| 119 |
st.success(f"Engine working normal. Probability: {prob:.2f}")
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
if st.button("Save Record"):
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
|
| 142 |
-
|
| 143 |
|
| 144 |
-
else:
|
| 145 |
-
|
| 146 |
|
|
|
|
| 91 |
# Predict Button
|
| 92 |
# -----------------------------
|
| 93 |
if submit:
|
| 94 |
+
input_df = pd.DataFrame({
|
|
|
|
| 95 |
"engine_rpm": [engine_rpm],
|
| 96 |
"lub_oil_pressure": [lub_oil_pressure],
|
| 97 |
"fuel_pressure": [fuel_pressure],
|
|
|
|
| 100 |
"coolant_temp": [coolant_temp]
|
| 101 |
})
|
| 102 |
|
| 103 |
+
st.success("✅ Input captured successfully")
|
| 104 |
+
st.write("### Input Data")
|
| 105 |
+
st.dataframe(input_df)
|
| 106 |
|
| 107 |
+
# Predict
|
| 108 |
+
prediction = model.predict(input_df)[0]
|
| 109 |
+
prob = model.predict_proba(input_df)[0][1]
|
| 110 |
|
| 111 |
+
st.subheader("Prediction Result")
|
| 112 |
|
| 113 |
+
if prob>=0.5:
|
| 114 |
label="Maintenance Needed"
|
| 115 |
st.warning(f"Engine needs Preventive maintenance. Probability: {prob:.2f}")
|
| 116 |
+
else:
|
| 117 |
label="Normal"
|
| 118 |
st.success(f"Engine working normal. Probability: {prob:.2f}")
|
| 119 |
|
| 120 |
+
# Save prediction to dataframe
|
| 121 |
+
input_df['Engine_condition'] = label #'Normal / Preventive maintenance req '
|
| 122 |
+
st.session_state['input_df'] = input_df
|
| 123 |
+
st.dataframe(input_df)
|
| 124 |
+
# -----------------------------
|
| 125 |
+
# SAVE RECORDS SECTION
|
| 126 |
+
# -----------------------------
|
| 127 |
+
if st.button("Save Record"):
|
| 128 |
+
if "input_df" in st.session_state:
|
| 129 |
+
file_path = "records.csv"
|
| 130 |
+
|
| 131 |
+
# If file exists → append
|
| 132 |
+
if os.path.exists(file_path):
|
| 133 |
+
existing_df = pd.read_csv(file_path)
|
| 134 |
+
updated_df = pd.concat([existing_df, input_df], ignore_index=True)
|
| 135 |
+
else:
|
| 136 |
+
# Create new CSV
|
| 137 |
+
updated_df = st.session_state['input_df']
|
| 138 |
|
| 139 |
+
updated_df.to_csv(file_path, index=False)
|
| 140 |
|
| 141 |
+
st.success("Record saved successfully!")
|
| 142 |
|
| 143 |
+
else:
|
| 144 |
+
st.error("Record not saved...Thank for analysis")
|
| 145 |
|