Spaces:
Configuration error
Configuration error
Update app.py
Browse files
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 |
-
#
|
| 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 |
-
#
|
| 65 |
-
|
|
|
|
| 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()
|