Xantoss commited on
Commit
b812050
·
verified ·
1 Parent(s): 2c5c0ce

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -3,25 +3,38 @@ import joblib
3
  import pandas as pd
4
  import gradio as gr
5
 
6
- # Charger le modele depuis Hugging Face
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
11
  def predict(PropertyGFATotal, PrimaryPropertyType, BuildingAge, NumberofFloors, NumberofBuildings, PctElec, PctSteam):
12
- df = pd.DataFrame([{
13
- "PropertyGFATotal": PropertyGFATotal,
14
- "PrimaryPropertyType": PrimaryPropertyType,
15
- "BuildingAge": BuildingAge,
16
- "NumberofFloors": NumberofFloors,
17
- "NumberofBuildings": NumberofBuildings,
18
- "PctElec": PctElec,
19
- "PctSteam": PctSteam
20
- }])
21
- prediction = model.predict(df)[0]
22
- return f"{prediction:,.0f} kBtu"
 
 
 
 
 
 
 
 
 
 
23
 
24
- # Interface Gradio
 
 
 
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=[