Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -3,25 +3,38 @@ import joblib
|
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
#
|
| 7 |
model_path = hf_hub_download(repo_id="Xantoss/energy_model", filename="model.joblib")
|
| 8 |
model = joblib.load(model_path)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
def predict(PropertyGFATotal, PrimaryPropertyType, BuildingAge, NumberofFloors, NumberofBuildings, PctElec, PctSteam):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=predict,
|
| 27 |
inputs=[
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
# charger le modele depuis Hugging Face Xantoss/energy_model
|
| 7 |
model_path = hf_hub_download(repo_id="Xantoss/energy_model", filename="model.joblib")
|
| 8 |
model = joblib.load(model_path)
|
| 9 |
|
| 10 |
+
#fonction de prediction avec verifications
|
| 11 |
def predict(PropertyGFATotal, PrimaryPropertyType, BuildingAge, NumberofFloors, NumberofBuildings, PctElec, PctSteam):
|
| 12 |
+
try:
|
| 13 |
+
#verifications manuelles
|
| 14 |
+
assert PropertyGFATotal > 0, "La surface doit être > 0"
|
| 15 |
+
assert 0 <= BuildingAge <= 200, "Âge du bâtiment entre 0 et 200 ans"
|
| 16 |
+
assert NumberofFloors >= 1, "Le nombre d'étages doit être ≥ 1"
|
| 17 |
+
assert NumberofBuildings >= 1, "Le nombre de bâtiments doit être ≥ 1"
|
| 18 |
+
assert 0 <= PctElec <= 1, "Part électrique entre 0 et 1"
|
| 19 |
+
assert 0 <= PctSteam <= 1, "Part vapeur entre 0 et 1"
|
| 20 |
+
assert PctElec + PctSteam <= 1, "PctElec + PctSteam doit être ≤ 1"
|
| 21 |
+
|
| 22 |
+
df = pd.DataFrame([{
|
| 23 |
+
"PropertyGFATotal": PropertyGFATotal,
|
| 24 |
+
"PrimaryPropertyType": PrimaryPropertyType,
|
| 25 |
+
"BuildingAge": BuildingAge,
|
| 26 |
+
"NumberofFloors": NumberofFloors,
|
| 27 |
+
"NumberofBuildings": NumberofBuildings,
|
| 28 |
+
"PctElec": PctElec,
|
| 29 |
+
"PctSteam": PctSteam
|
| 30 |
+
}])
|
| 31 |
+
prediction = model.predict(df)[0]
|
| 32 |
+
return f"{prediction:,.0f} kBtu"
|
| 33 |
|
| 34 |
+
except AssertionError as e:
|
| 35 |
+
return f"Erreur : {e}"
|
| 36 |
+
|
| 37 |
+
# interface Gradio
|
| 38 |
demo = gr.Interface(
|
| 39 |
fn=predict,
|
| 40 |
inputs=[
|