Spaces:
Sleeping
Sleeping
github-actions commited on
Commit ·
9a6bc35
1
Parent(s): 042d07b
Deploy from GitHub Actions
Browse files1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566672 unmodified lines70717273747576771 unmodified lineimport joblibimport pandas as pdimport gradio as grfrom huggingface_hub import hf_hub_download# Hugging Face Model RepositoryREPO_ID = "Swetha1929/predictive-maintenance-engine-model"# Load modelmodel_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()]# Load model information (optional)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 = {}def predict(*values):input_df = pd.DataFrame([list(values)], columns=feature_names)prediction = model.predict(input_df)[0]if hasattr(model, "predict_proba"):probabilities = model.predict_proba(input_df)[0]probability_dict = {f"Class {i}": float(prob)for i, prob in enumerate(probabilities)}return prediction, probability_dictreturn prediction, {}# Create one input box for every featureinputs = [gr.Number(label=feature)for feature in feature_names]# Gradio Interfacedemo = gr.Interface(fn=predict,inputs=inputs,2 unmodified linesgr.Label(label="Prediction Probabilities")],title="Engine Condition Prediction",description="Enter the engine feature values to predict the engine condition.")# Launch applicationdemo.launch()1 unmodified line23456789101112131415161718192021222324252627282930313233343536373839402 unmodified lines434445464748491 unmodified lineimport joblibimport pandas as pdimport gradio as grimport spacesfrom huggingface_hub import hf_hub_downloadREPO_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.GPUdef 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,2 unmodified linesgr.Label(label="Prediction Probabilities")],title="Engine Condition Prediction",description="Enter engine parameters to predict the engine condition.")demo.launch()
app.py+10-38