DevNumb commited on
Commit
07806b1
·
verified ·
1 Parent(s): f53a130

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -26
app.py CHANGED
@@ -1,25 +1,18 @@
1
  import gradio as gr
2
- import pickle
3
  import pandas as pd
4
  import numpy as np
 
5
  from huggingface_hub import hf_hub_download
6
 
7
- # Download model from MODEL repository (not stored in Space)
8
- repo_id = "DevNumb/random-forest-model-reduced" # Your MODEL repo
 
9
 
10
- print("Downloading model (1.64 GB)...")
11
- model_path = hf_hub_download(
12
- repo_id=repo_id,
13
- filename="random_forest_model_reduced.pkl",
14
- local_dir="/tmp/model" # Downloads to Space's 50 GB disk
15
- )
16
-
17
- print("Loading model...")
18
- with open(model_path, 'rb') as f:
19
- model = pickle.load(f)
20
- print("✅ Model ready!")
21
 
22
- # Feature names from your JSON
23
  FEATURE_NAMES = [
24
  'OA_TEMP', 'OA_TEMP_WB', 'Hour', 'Weekday', 'Month',
25
  'CHL_STA_1', 'CHL_STA_2', 'CHL_STA_3',
@@ -30,26 +23,21 @@ FEATURE_NAMES = [
30
  ]
31
 
32
  def predict(*args):
 
33
  input_data = pd.DataFrame([list(args)], columns=FEATURE_NAMES)
34
  prediction = model.predict(input_data)[0]
35
-
36
- try:
37
- probabilities = model.predict_proba(input_data)[0]
38
- confidence = np.max(probabilities)
39
- result = f"**Prediction:** {prediction:.2f}\n\n**Confidence:** {confidence:.2%}"
40
- except:
41
- result = f"**Prediction:** {prediction}"
42
-
43
- return result
44
 
45
- # Create input fields for all 18 features
46
  inputs = [gr.Number(label=name) for name in FEATURE_NAMES]
47
 
 
48
  demo = gr.Interface(
49
  fn=predict,
50
  inputs=inputs,
51
  outputs=gr.Markdown(label="Result"),
52
- title="HVAC Chiller System Prediction API"
 
53
  )
54
 
55
  demo.launch()
 
1
  import gradio as gr
 
2
  import pandas as pd
3
  import numpy as np
4
+ import joblib
5
  from huggingface_hub import hf_hub_download
6
 
7
+ # Download model from your repository
8
+ repo_id = "DevNumb/random-forest-model-reduced"
9
+ model_path = hf_hub_download(repo_id=repo_id, filename="model.joblib")
10
 
11
+ # Load model
12
+ model = joblib.load(model_path)
13
+ print("✅ Model loaded successfully!")
 
 
 
 
 
 
 
 
14
 
15
+ # Your 18 feature names
16
  FEATURE_NAMES = [
17
  'OA_TEMP', 'OA_TEMP_WB', 'Hour', 'Weekday', 'Month',
18
  'CHL_STA_1', 'CHL_STA_2', 'CHL_STA_3',
 
23
  ]
24
 
25
  def predict(*args):
26
+ """Make prediction from 18 features"""
27
  input_data = pd.DataFrame([list(args)], columns=FEATURE_NAMES)
28
  prediction = model.predict(input_data)[0]
29
+ return f"**Prediction:** {prediction:.2f}"
 
 
 
 
 
 
 
 
30
 
31
+ # Create input fields
32
  inputs = [gr.Number(label=name) for name in FEATURE_NAMES]
33
 
34
+ # Create interface
35
  demo = gr.Interface(
36
  fn=predict,
37
  inputs=inputs,
38
  outputs=gr.Markdown(label="Result"),
39
+ title="HVAC Chiller Prediction API",
40
+ description="Predicts chiller system performance"
41
  )
42
 
43
  demo.launch()