Spaces:
Runtime error
Runtime error
Sync App files
Browse files- README.md +6 -8
- drug_app.py +56 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
---
|
| 2 |
title: Drug Classification
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: Drug Classification
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.16.0
|
| 8 |
+
app_file: drug_app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
---
|
|
|
|
|
|
drug_app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import skops.io as sio
|
| 3 |
+
|
| 4 |
+
pipe = sio.load("./Model/drug_pipeline.skops", trusted=True)
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):
|
| 8 |
+
"""Predict drugs based on patient features.
|
| 9 |
+
Args:
|
| 10 |
+
age (int): Age of patient
|
| 11 |
+
sex (str): Sex of patient
|
| 12 |
+
blood_pressure (str): Blood pressure level
|
| 13 |
+
cholesterol (str): Cholesterol level
|
| 14 |
+
na_to_k_ratio (float): Ratio of sodium to potassium in blood
|
| 15 |
+
Returns:
|
| 16 |
+
str: Predicted drug label
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
|
| 20 |
+
predicted_drug = pipe.predict([features])[0]
|
| 21 |
+
|
| 22 |
+
label = f"Predicted Drug: {predicted_drug}"
|
| 23 |
+
return label
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
inputs = [
|
| 27 |
+
gr.Slider(15, 74, step=1, label="Age"),
|
| 28 |
+
gr.Radio(["M", "F"], label="Sex"),
|
| 29 |
+
gr.Radio(["HIGH", "LOW", "NORMAL"], label="Blood Pressure"),
|
| 30 |
+
gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
|
| 31 |
+
gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
|
| 32 |
+
]
|
| 33 |
+
outputs = [gr.Label(num_top_classes=5)]
|
| 34 |
+
|
| 35 |
+
examples = [
|
| 36 |
+
[30, "M", "HIGH", "NORMAL", 15.4],
|
| 37 |
+
[35, "F", "LOW", "NORMAL", 8],
|
| 38 |
+
[50, "M", "HIGH", "HIGH", 34],
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
title = "Drug Classification"
|
| 43 |
+
description = "Enter the details to correctly identify Drug type?"
|
| 44 |
+
article = "This app is a part of the Beginner's Guide to CI/CD for Machine Learning. It teaches how to automate training, evaluation, and deployment of models to Hugging Face using GitHub Actions."
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
gr.Interface(
|
| 48 |
+
fn=predict_drug,
|
| 49 |
+
inputs=inputs,
|
| 50 |
+
outputs=outputs,
|
| 51 |
+
examples=examples,
|
| 52 |
+
title=title,
|
| 53 |
+
description=description,
|
| 54 |
+
article=article,
|
| 55 |
+
theme=gr.themes.Soft(),
|
| 56 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
scikit-learn
|
| 2 |
+
skops
|