lidorlg/Drug-Classification
0
1import gradio as gr2import skops.io as sio3unknown_types = sio.get_untrusted_types(file="./Model/drug_pipeline.skops")4pipe = sio.load("./Model/drug_pipeline.skops", trusted=unknown_types)5 6 7def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):8 """Predict drugs based on patient features.9 10 Args:11 age (int): Age of patient12 sex (str): Sex of patient13 blood_pressure (str): Blood pressure level14 cholesterol (str): Cholesterol level15 na_to_k_ratio (float): Ratio of sodium to potassium in blood16 17 Returns:18 str: Predicted drug label19 """20 features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]21 predicted_drug = pipe.predict([features])[0]22 23 label = f"Predicted Drug: {predicted_drug}"24 return label25 26 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 42 43title = "Drug Classification"44description = "Enter the details to correctly identify Drug type?"45article = "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."46 47 48gr.Interface(49 fn=predict_drug,50 inputs=inputs,51 outputs=outputs,52 examples=examples,53 title=title,54 description=description,55 article=article,56 theme=gr.themes.Soft(),57).launch()58 