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