Spaces:
Runtime error
Runtime error
File size: 1,993 Bytes
a3e16aa a65f3c1 a3e16aa 437a654 a3e16aa 6850293 a3e16aa a65f3c1 6850293 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import gradio as gr
import joblib
import pandas as pd
import numpy as np
import datetime
# Load trained model
model = joblib.load("GRADIENTBOOSTING_WITH_SMOTE_model.pkl")
def predict_outbreak(*inputs):
try:
inputs = list(inputs)
# Convert date to ordinal
inputs[0] = datetime.datetime.strptime(inputs[0], "%Y-%m-%d").toordinal()
inputs = np.array(inputs).reshape(1, -1)
prediction = model.predict(inputs)
return "Yes" if prediction[0] == 1 else "No"
except Exception as e:
return f"Error: {str(e)}"
input_components = [
gr.Textbox(label="Date (YYYY-MM-DD)"),
gr.Dropdown(["Winter", "Spring", "Summer", "Fall"], label="Season"),
gr.Textbox(label="State"),
gr.Number(label="Latitude"),
gr.Number(label="Longitude"),
gr.Number(label="Proximity to Water"),
gr.Number(label="Humidity (%)"),
gr.Checkbox(label="Wild Bird Migration Present"),
gr.Checkbox(label="Neighboring Farm Outbreak"),
gr.Dropdown(["Poultry", "Cattle", "Mixed", "Other"], label="Farm Type"),
gr.Number(label="Vaccination Rate (%)"),
gr.Number(label="Farm Size"),
gr.Dropdown(["Internal", "External"], label="Feed Source"),
gr.Dropdown(["River", "Well", "Tank", "Other"], label="Water Source"),
gr.Number(label="Temperature (°C)"),
gr.Checkbox(label="Recent Farm Visits"),
gr.Checkbox(label="Other Animals Present"),
gr.Number(label="Mortality Rate Last Week (%)"),
gr.Checkbox(label="Protective Equipment Used"),
gr.Dropdown(["Easy", "Difficult"], label="Farm Accessibility"),
gr.Checkbox(label="Previous Outbreak")
]
output_component = gr.Textbox(label="Outbreak Within 7 Days?")
demo = gr.Interface(
fn=predict_outbreak,
inputs=input_components,
outputs=output_component,
title="Avian Influenza Risk Prediction",
description="Predict avian influenza outbreak risk with a Gradient Boosting model."
)
# DO NOT call demo.launch() in Hugging Face Spaces
|