Sgobir commited on
Commit
6796633
·
verified ·
1 Parent(s): 42bf46f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -4,6 +4,7 @@ import pandas as pd
4
  import numpy as np
5
  import datetime
6
 
 
7
  model = joblib.load("RANDOMFOREST_model.pkl")
8
 
9
  # Predict function
@@ -14,10 +15,7 @@ def predict_outbreak(*inputs):
14
  date_input = datetime.datetime.strptime(inputs[0], "%Y-%m-%d").toordinal()
15
  inputs[0] = date_input
16
 
17
- # Optionally convert other categorical inputs if your model expects that
18
- # You may need to preprocess inputs based on how your model was trained
19
-
20
- # Convert all to float/int where possible
21
  processed_inputs = np.array(inputs).reshape(1, -1)
22
  prediction = model.predict(processed_inputs)
23
  return "Yes" if prediction[0] == 1 else "No"
@@ -49,10 +47,10 @@ input_components = [
49
  gr.Checkbox(label="Previous Outbreak")
50
  ]
51
 
52
- # Output
53
  output_component = gr.Textbox(label="Outbreak Within 7 Days?")
54
 
55
- # Interface
56
  demo = gr.Interface(
57
  fn=predict_outbreak,
58
  inputs=input_components,
@@ -61,5 +59,5 @@ demo = gr.Interface(
61
  description="Predict whether a farm will experience an outbreak in the next 7 days using a pre-trained Random Forest model."
62
  )
63
 
64
- # Uncomment this if running locally
65
- # demo.launch()
 
4
  import numpy as np
5
  import datetime
6
 
7
+ # Load trained model
8
  model = joblib.load("RANDOMFOREST_model.pkl")
9
 
10
  # Predict function
 
15
  date_input = datetime.datetime.strptime(inputs[0], "%Y-%m-%d").toordinal()
16
  inputs[0] = date_input
17
 
18
+ # Convert to NumPy array
 
 
 
19
  processed_inputs = np.array(inputs).reshape(1, -1)
20
  prediction = model.predict(processed_inputs)
21
  return "Yes" if prediction[0] == 1 else "No"
 
47
  gr.Checkbox(label="Previous Outbreak")
48
  ]
49
 
50
+ # Output component
51
  output_component = gr.Textbox(label="Outbreak Within 7 Days?")
52
 
53
+ # Gradio Interface
54
  demo = gr.Interface(
55
  fn=predict_outbreak,
56
  inputs=input_components,
 
59
  description="Predict whether a farm will experience an outbreak in the next 7 days using a pre-trained Random Forest model."
60
  )
61
 
62
+ # 🚨 This line is required for Hugging Face Spaces
63
+ demo.launch()