import logging import gradio as gr import pandas as pd from autogluon.tabular import TabularPredictor # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Load the AutoGluon model from the Hugging Face Hub MODEL_ID = "aai540-group3/diabetes-readmission" predictor = TabularPredictor.load(MODEL_ID) # Define constants for the Gradio interface AGE_RANGE = (0, 100) TIME_IN_HOSPITAL_RANGE = (1, 14) NUM_PROCEDURES_RANGE = (0, 10) NUM_MEDICATIONS_RANGE = (0, 20) NUMBER_DIAGNOSES_RANGE = (1, 10) READMITTED_CHOICES = ["<30", ">30", "NO"] # Define the inference function def predict( age, time_in_hospital, num_procedures, num_medications, number_diagnoses, metformin, repaglinide, nateglinide, chlorpropamide, glimepiride, glipizide, glyburide, pioglitazone, rosiglitazone, acarbose, insulin, readmitted ): # Create a DataFrame from the input features input_data = pd.DataFrame([{ "age": age, "time_in_hospital": time_in_hospital, "num_procedures": num_procedures, "num_medications": num_medications, "number_diagnoses": number_diagnoses, "metformin": int(metformin), "repaglinide": int(repaginide), "nateglinide": int(nateglinide), "chlorpropamide": int(chlorpropamide), "glimepiride": int(glimepiride), "glipizide": int(glipizide), "glyburide": int(glyburide), "pioglitazone": int(pioglitazone), "rosiglitazone": int(rosiglitazone), "acarbose": int(acarbose), "insulin": int(insulin), "readmitted": readmitted }]) try: # Make a prediction using the AutoGluon predictor prediction = predictor.predict(input_data) logger.info(f"Prediction received: {prediction}") return f"