Xantoss's picture
Upload app.py
b812050 verified
from huggingface_hub import hf_hub_download
import joblib
import pandas as pd
import gradio as gr
# charger le modele depuis Hugging Face Xantoss/energy_model
model_path = hf_hub_download(repo_id="Xantoss/energy_model", filename="model.joblib")
model = joblib.load(model_path)
#fonction de prediction avec verifications
def predict(PropertyGFATotal, PrimaryPropertyType, BuildingAge, NumberofFloors, NumberofBuildings, PctElec, PctSteam):
try:
#verifications manuelles
assert PropertyGFATotal > 0, "La surface doit être > 0"
assert 0 <= BuildingAge <= 200, "Âge du bâtiment entre 0 et 200 ans"
assert NumberofFloors >= 1, "Le nombre d'étages doit être ≥ 1"
assert NumberofBuildings >= 1, "Le nombre de bâtiments doit être ≥ 1"
assert 0 <= PctElec <= 1, "Part électrique entre 0 et 1"
assert 0 <= PctSteam <= 1, "Part vapeur entre 0 et 1"
assert PctElec + PctSteam <= 1, "PctElec + PctSteam doit être ≤ 1"
df = pd.DataFrame([{
"PropertyGFATotal": PropertyGFATotal,
"PrimaryPropertyType": PrimaryPropertyType,
"BuildingAge": BuildingAge,
"NumberofFloors": NumberofFloors,
"NumberofBuildings": NumberofBuildings,
"PctElec": PctElec,
"PctSteam": PctSteam
}])
prediction = model.predict(df)[0]
return f"{prediction:,.0f} kBtu"
except AssertionError as e:
return f"Erreur : {e}"
# interface Gradio
demo = gr.Interface(
fn=predict,
inputs=[
gr.Number(label="Surface totale"),
gr.Textbox(label="Type de bâtiment (ex: Hotel)"),
gr.Number(label="Âge du bâtiment"),
gr.Number(label="Nombre d'étages"),
gr.Number(label="Nombre de bâtiments"),
gr.Slider(0, 1, step=0.01, label="Part Électrique"),
gr.Slider(0, 1, step=0.01, label="Part Vapeur")
],
outputs="text",
title="Prédiction énergétique de bâtiments",
description="Modèle de Gradient Boosting optimisé. Entrez les infos du bâtiment pour estimer la consommation (kBtu)."
)
demo.launch()