Spaces:
Sleeping
Sleeping
GitHub Actions Bot commited on
Commit ·
2afe624
1
Parent(s): e52ec48
feat: Deploy latest version of Gradio app
Browse files- app.py +28 -12
- app_old.py → app_v2.py +0 -0
- app_v3.py +98 -0
- engine.jpg +0 -0
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import joblib
|
| 3 |
import numpy as np
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# --- 1. Load the Pre-Trained Model ---
|
| 7 |
# This script assumes 'model.joblib' exists because you've run train.py
|
|
@@ -27,44 +28,59 @@ feature_names = [
|
|
| 27 |
# --- 3. Create the Prediction Function ---
|
| 28 |
def predict_rul(*args):
|
| 29 |
"""
|
| 30 |
-
Takes all 24
|
| 31 |
correct format, and returns the model's RUL prediction.
|
| 32 |
"""
|
| 33 |
if model is None:
|
| 34 |
return "Model not loaded. Please run 'python train.py' and restart the app."
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
prediction = model.predict(input_data)
|
| 38 |
final_prediction = prediction[0]
|
| 39 |
|
| 40 |
return f"{round(final_prediction, 2)} cycles remaining"
|
| 41 |
|
|
|
|
| 42 |
# --- 4. Build the Gradio Interface ---
|
| 43 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 44 |
-
gr.Markdown("#
|
| 45 |
gr.Markdown(
|
| 46 |
"""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
"""
|
| 51 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
gr.Markdown("###
|
| 54 |
|
| 55 |
-
# Create
|
| 56 |
inputs = []
|
| 57 |
-
# Arrange the number inputs into a 3-column grid for a more compact layout
|
| 58 |
num_columns = 3
|
| 59 |
for i in range(0, len(feature_names), num_columns):
|
| 60 |
with gr.Row():
|
| 61 |
for j in range(num_columns):
|
| 62 |
if i + j < len(feature_names):
|
| 63 |
name = feature_names[i + j]
|
| 64 |
-
|
| 65 |
-
component = gr.Number(label=name, value=0.0)
|
| 66 |
inputs.append(component)
|
| 67 |
-
|
| 68 |
# Place the prediction button below the inputs
|
| 69 |
predict_btn = gr.Button("Predict RUL", variant="primary")
|
| 70 |
|
|
|
|
| 2 |
import joblib
|
| 3 |
import numpy as np
|
| 4 |
import os
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
# --- 1. Load the Pre-Trained Model ---
|
| 8 |
# This script assumes 'model.joblib' exists because you've run train.py
|
|
|
|
| 28 |
# --- 3. Create the Prediction Function ---
|
| 29 |
def predict_rul(*args):
|
| 30 |
"""
|
| 31 |
+
Takes all 24 number inputs as arguments, arranges them into the
|
| 32 |
correct format, and returns the model's RUL prediction.
|
| 33 |
"""
|
| 34 |
if model is None:
|
| 35 |
return "Model not loaded. Please run 'python train.py' and restart the app."
|
| 36 |
|
| 37 |
+
# Ensure all inputs are converted to float, handling None or empty strings
|
| 38 |
+
processed_args = [float(arg) if arg is not None and arg != '' else 0.0 for arg in args]
|
| 39 |
+
|
| 40 |
+
input_data = np.array(processed_args).reshape(1, -1)
|
| 41 |
prediction = model.predict(input_data)
|
| 42 |
final_prediction = prediction[0]
|
| 43 |
|
| 44 |
return f"{round(final_prediction, 2)} cycles remaining"
|
| 45 |
|
| 46 |
+
|
| 47 |
# --- 4. Build the Gradio Interface ---
|
| 48 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 49 |
+
gr.Markdown("# North Star 1.0")
|
| 50 |
gr.Markdown(
|
| 51 |
"""
|
| 52 |
+
Predictive maintenance machine learning system, forecasting faults and remaining useful life (RUL).
|
| 53 |
+
|
| 54 |
+
Demo parameters trained on aircraft turbo fan engine dataset (NASA FD001 file).
|
| 55 |
+
|
| 56 |
+
Model automatically trains on dataset upon launch.
|
| 57 |
+
|
| 58 |
"""
|
| 59 |
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# --- NEW: Video Display ---
|
| 63 |
+
# This component will display your video.
|
| 64 |
+
gr.Video(
|
| 65 |
+
value="intro.mp4", #
|
| 66 |
+
label="Customizable for multiple machines",
|
| 67 |
+
autoplay=True, # Optional: makes the video play automatically
|
| 68 |
+
interactive=False # Optional: prevents users from uploading their own video
|
| 69 |
+
)
|
| 70 |
|
| 71 |
+
gr.Markdown("### Enter Machine Parameters & Sensor Readings")
|
| 72 |
|
| 73 |
+
# Create the user inputs in a grid
|
| 74 |
inputs = []
|
|
|
|
| 75 |
num_columns = 3
|
| 76 |
for i in range(0, len(feature_names), num_columns):
|
| 77 |
with gr.Row():
|
| 78 |
for j in range(num_columns):
|
| 79 |
if i + j < len(feature_names):
|
| 80 |
name = feature_names[i + j]
|
| 81 |
+
component = gr.Number(label=name, value=50.0)
|
|
|
|
| 82 |
inputs.append(component)
|
| 83 |
+
|
| 84 |
# Place the prediction button below the inputs
|
| 85 |
predict_btn = gr.Button("Predict RUL", variant="primary")
|
| 86 |
|
app_old.py → app_v2.py
RENAMED
|
File without changes
|
app_v3.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# --- 1. Load the Pre-Trained Model ---
|
| 7 |
+
# This script assumes 'model.joblib' exists because you've run train.py
|
| 8 |
+
MODEL_PATH = "model.joblib"
|
| 9 |
+
model = None
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
model = joblib.load(MODEL_PATH)
|
| 13 |
+
print("Model 'model.joblib' loaded successfully.")
|
| 14 |
+
except FileNotFoundError:
|
| 15 |
+
print(f"ERROR: Model file not found at '{MODEL_PATH}'.")
|
| 16 |
+
print("Please run 'python train.py' in your terminal first to create the model file.")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# --- 2. Define Feature Names ---
|
| 20 |
+
# This list must be in the exact same order as the data your model was trained on.
|
| 21 |
+
feature_names = [
|
| 22 |
+
'time_in_cycles', 'setting_1', 'setting_2', 's_1', 's_2', 's_3', 's_4', 's_5',
|
| 23 |
+
's_6', 's_7', 's_8', 's_9', 's_10', 's_11', 's_12', 's_13', 's_14', 's_15',
|
| 24 |
+
's_16', 's_17', 's_18', 's_19', 's_20', 's_21'
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
# --- 3. Create the Prediction Function ---
|
| 28 |
+
def predict_rul(*args):
|
| 29 |
+
"""
|
| 30 |
+
Takes all 24 slider/number inputs as arguments, arranges them into the
|
| 31 |
+
correct format, and returns the model's RUL prediction.
|
| 32 |
+
"""
|
| 33 |
+
if model is None:
|
| 34 |
+
return "Model not loaded. Please run 'python train.py' and restart the app."
|
| 35 |
+
|
| 36 |
+
input_data = np.array(args).reshape(1, -1)
|
| 37 |
+
prediction = model.predict(input_data)
|
| 38 |
+
final_prediction = prediction[0]
|
| 39 |
+
|
| 40 |
+
return f"{round(final_prediction, 2)} cycles remaining"
|
| 41 |
+
|
| 42 |
+
# --- 4. Build the Gradio Interface ---
|
| 43 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 44 |
+
gr.Markdown("# North Star 1.0")
|
| 45 |
+
gr.Markdown(
|
| 46 |
+
"""
|
| 47 |
+
Predictive maintenance machine learning system, forecasting faults and remaining useful life (RUL).
|
| 48 |
+
|
| 49 |
+
Demo parameters trained on aircraft turbo fan engine dataset (NASA FD001 file).
|
| 50 |
+
|
| 51 |
+
Model automatically trains on dataset upon launch.
|
| 52 |
+
|
| 53 |
+
"""
|
| 54 |
+
)
|
| 55 |
+
# This component will display your four images in a neat grid.
|
| 56 |
+
gr.Gallery(
|
| 57 |
+
value=["https://images.pexels.com/photos/28084075/pexels-photo-28084075.jpeg"],
|
| 58 |
+
label="Customize easily for almost any machinery",
|
| 59 |
+
columns=1, # Arrange images in 4 columns
|
| 60 |
+
object_fit="cover",
|
| 61 |
+
height="10"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
gr.Markdown("### Engine Parameters & Sensor Readings")
|
| 68 |
+
|
| 69 |
+
# Create a list to hold all our input components in a single column
|
| 70 |
+
inputs = []
|
| 71 |
+
# Arrange the number inputs into a 3-column grid for a more compact layout
|
| 72 |
+
num_columns = 3
|
| 73 |
+
for i in range(0, len(feature_names), num_columns):
|
| 74 |
+
with gr.Row():
|
| 75 |
+
for j in range(num_columns):
|
| 76 |
+
if i + j < len(feature_names):
|
| 77 |
+
name = feature_names[i + j]
|
| 78 |
+
# Create the component and add it to our list of inputs
|
| 79 |
+
component = gr.Number(label=name, value=0.0)
|
| 80 |
+
inputs.append(component)
|
| 81 |
+
|
| 82 |
+
# Place the prediction button below the inputs
|
| 83 |
+
predict_btn = gr.Button("Predict RUL", variant="primary")
|
| 84 |
+
|
| 85 |
+
gr.Markdown("### Prediction Result")
|
| 86 |
+
# Create the output textbox below the button
|
| 87 |
+
outputs = gr.Textbox(label="Predicted Remaining Useful Life (RUL)")
|
| 88 |
+
|
| 89 |
+
# Connect the button's "click" event to our prediction function
|
| 90 |
+
predict_btn.click(
|
| 91 |
+
fn=predict_rul,
|
| 92 |
+
inputs=inputs,
|
| 93 |
+
outputs=outputs
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# --- 5. Launch the App ---
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
demo.launch()
|
engine.jpg
DELETED