Spaces:
Sleeping
Sleeping
File size: 1,484 Bytes
5b74bae d8ad157 5bdf006 5b74bae b9bce10 d8ad157 7f06bf5 d8ad157 7f06bf5 d8ad157 7f06bf5 d8ad157 7f06bf5 d8ad157 b6d069c 5b74bae b6d069c d8ad157 f8227ba d8ad157 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import json
import joblib
import pandas as pd
import gradio as gr
import spaces
from huggingface_hub import hf_hub_download
REPO_ID = "Swetha1929/predictive-maintenance-engine-model"
model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pkl")
feature_path = hf_hub_download(repo_id=REPO_ID, filename="feature_names.txt")
model = joblib.load(model_path)
with open(feature_path, "r", encoding="utf-8") as f:
feature_names = [line.strip() for line in f if line.strip()]
try:
info_path = hf_hub_download(repo_id=REPO_ID, filename="model_info.json")
with open(info_path, "r", encoding="utf-8") as f:
model_info = json.load(f)
except Exception:
model_info = {}
@spaces.GPU
def predict(*values):
input_df = pd.DataFrame([list(values)], columns=feature_names)
prediction = model.predict(input_df)[0]
if hasattr(model, "predict_proba"):
probs = model.predict_proba(input_df)[0]
return str(prediction), {f"Class {i}": float(p) for i, p in enumerate(probs)}
return str(prediction), {}
inputs = [gr.Number(label=feature) for feature in feature_names]
demo = gr.Interface(
fn=predict,
inputs=inputs,
outputs=[
gr.Textbox(label="Predicted Engine Condition"),
gr.Label(label="Prediction Probabilities")
],
title="Engine Condition Prediction",
description="Enter engine parameters to predict the engine condition."
)
demo.launch()
|