mlcicd/Drug-Classification
0
1import gradio as gr2import skops.io as sio3 4# Get the untrusted types5untrusted_types = sio.get_untrusted_types(file="./Model/drug_pipeline.skops")6 7pipe = sio.load("./Model/drug_pipeline.skops", trusted=untrusted_types)8 9 10def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):11 """Predict drugs based on patient features.12 Args:13 age (int): Age of patient14 sex (str): Sex of patient15 blood_pressure (str): Blood pressure level16 cholesterol (str): Cholesterol level17 na_to_k_ratio (float): Ratio of sodium to potassium in blood18 Returns:19 str: Predicted drug label20 """21 features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]22 predicted_drug = pipe.predict([features])[0]23 24 label = f"Predicted Drug: {predicted_drug}"25 return label26 27inputs = [28 gr.Slider(15, 74, step=1, label="Age"),29 gr.Radio(["M", "F"], label="Sex"),30 gr.Radio(["HIGH", "LOW", "NORMAL"], label="Blood Pressure"),31 gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),32 gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),33]34outputs = [gr.Label(num_top_classes=5)]35 36examples = [37 [30, "M", "HIGH", "NORMAL", 15.4],38 [35, "F", "LOW", "NORMAL", 8],39 [50, "M", "HIGH", "HIGH", 34],40]41 42title = "Drug Classification"43description = "Enter the details to correctly identify Drug type?"44article = "This app is a part of the **[Beginner's Guide to CI/CD for Machine Learning](https://www.datacamp.com/tutorial/ci-cd-for-machine-learning)**. It teaches how to automate training, evaluation, and deployment of models to Hugging Face using GitHub Actions."45 46gr.Interface(47 fn=predict_drug,48 inputs=inputs,49 outputs=outputs,50 examples=examples,51 title=title,52 description=description,53 article=article,54 theme=gr.themes.Soft(),55).launch()