File size: 2,203 Bytes
2c5c0ce
 
 
 
 
b812050
2c5c0ce
 
 
b812050
2c5c0ce
b812050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c5c0ce
b812050
 
 
 
2c5c0ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
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()