Vbhadiar commited on
Commit
8f54a04
·
verified ·
1 Parent(s): 3a346fa

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +54 -3
app.py CHANGED
@@ -1,3 +1,54 @@
1
- # Your Gradio/Streamlit app here
2
- import gradio as gr
3
- gr.Interface(lambda x: x, "text", "text").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import joblib
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ HF_USERNAME = "Vbhadiar"
8
+ MODEL_ID = f"{HF_USERNAME}/engine-failure-classifier"
9
+
10
+ @st.cache_resource
11
+ def load_model():
12
+ model_path = hf_hub_download(
13
+ repo_id=MODEL_ID,
14
+ filename="best_model.pkl",
15
+ repo_type="model"
16
+ )
17
+ return joblib.load(model_path)
18
+
19
+ model = load_model()
20
+
21
+ st.title("🔧 Engine Predictive Maintenance")
22
+ st.markdown("Predict whether an engine requires maintenance based on sensor readings.")
23
+
24
+ col1, col2 = st.columns(2)
25
+
26
+ with col1:
27
+ engine_rpm = st.number_input("Engine RPM", 0, 3000, 800)
28
+ lub_oil_pressure = st.number_input("Lub Oil Pressure (bar)", 0.0, 10.0, 3.5, 0.1)
29
+ fuel_pressure = st.number_input("Fuel Pressure (bar)", 0.0, 25.0, 7.0, 0.1)
30
+
31
+ with col2:
32
+ coolant_pressure = st.number_input("Coolant Pressure (bar)", 0.0, 10.0, 2.5, 0.1)
33
+ lub_oil_temp = st.number_input("Lub Oil Temp (°C)", 50.0, 120.0, 78.0, 0.5)
34
+ coolant_temp = st.number_input("Coolant Temp (°C)", 50.0, 200.0, 80.0, 0.5)
35
+
36
+ if st.button("Predict"):
37
+ df_input = pd.DataFrame({
38
+ "engine_rpm": [engine_rpm],
39
+ "lub_oil_pressure": [lub_oil_pressure],
40
+ "fuel_pressure": [fuel_pressure],
41
+ "coolant_pressure": [coolant_pressure],
42
+ "lub_oil_temp": [lub_oil_temp],
43
+ "coolant_temp": [coolant_temp],
44
+ })
45
+ pred = model.predict(df_input)[0]
46
+ prob = model.predict_proba(df_input)[0][1]
47
+
48
+ if pred == 1:
49
+ st.error(f"⚠️ Maintenance required (failure probability: {prob*100:.1f}%)")
50
+ else:
51
+ st.success(f"✅ Engine normal (failure probability: {prob*100:.1f}% ")
52
+
53
+ st.write("Input data:")
54
+ st.dataframe(df_input)