manuelcastiblan commited on
Commit
6418a2e
·
verified ·
1 Parent(s): f3c03e9

Sync App files

Browse files
Files changed (3) hide show
  1. README.md +12 -4
  2. drug_app.py +74 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,13 +1,21 @@
1
  ---
2
  title: Drug Classification
3
- emoji: 🐠
4
  colorFrom: yellow
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 5.28.0
8
- app_file: app.py
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: 5.7.1
8
+ app_file: drug_app.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
12
 
13
+ *Learn how to automate model training, evaluation, versioning, and deployment using GitHub Actions with the easiest MLOps guide available online.*
14
+
15
+ > **Follow the tutorial:** https://www.datacamp.com/tutorial/ci-cd-for-machine-learning
16
+
17
+ ## Project Description
18
+ In this project, we will be using scikit-learn pipelines to train our random forest algorithm and build a drug classifier. After training, we will automate the evaluation process using CML. Finally, we will build and deploy the web application to Hugging Face Hub.
19
+
20
+ From training to evaluation, the entire process will be automated using GitHub actions. All you have to do is push the code to your GitHub repository, and within two minutes, the model will be updated on Hugging Face with the updated app, model, and results.
21
+
drug_app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import skops.io as sio
3
+ import warnings
4
+ from sklearn.exceptions import InconsistentVersionWarning
5
+
6
+ # Suppress the version warnings
7
+ warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
8
+
9
+ # Explicitly specify trusted types
10
+ trusted_types = [
11
+ "sklearn.pipeline.Pipeline",
12
+ "sklearn.preprocessing.OneHotEncoder",
13
+ "sklearn.preprocessing.StandardScaler",
14
+ "sklearn.compose.ColumnTransformer",
15
+ "sklearn.preprocessing.OrdinalEncoder",
16
+ "sklearn.impute.SimpleImputer",
17
+ "sklearn.tree.DecisionTreeClassifier",
18
+ "sklearn.ensemble.RandomForestClassifier",
19
+ "numpy.dtype",
20
+ ]
21
+ pipe = sio.load("./Model/drug_pipeline.skops", trusted=trusted_types)
22
+
23
+
24
+ def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):
25
+ """Predict drugs based on patient features.
26
+
27
+ Args:
28
+ age (int): Age of patient
29
+ sex (str): Sex of patient
30
+ blood_pressure (str): Blood pressure level
31
+ cholesterol (str): Cholesterol level
32
+ na_to_k_ratio (float): Ratio of sodium to potassium in blood
33
+
34
+ Returns:
35
+ str: Predicted drug label
36
+ """
37
+ features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
38
+ predicted_drug = pipe.predict([features])[0]
39
+
40
+ label = f"Predicted Drug: {predicted_drug}"
41
+ return label
42
+
43
+
44
+ inputs = [
45
+ gr.Slider(15, 74, step=1, label="Age"),
46
+ gr.Radio(["M", "F"], label="Sex"),
47
+ gr.Radio(["HIGH", "LOW", "NORMAL"], label="Blood Pressure"),
48
+ gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
49
+ gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
50
+ ]
51
+ outputs = [gr.Label(num_top_classes=5)]
52
+
53
+ examples = [
54
+ [30, "M", "HIGH", "NORMAL", 15.4],
55
+ [35, "F", "LOW", "NORMAL", 8],
56
+ [50, "M", "HIGH", "HIGH", 34],
57
+ ]
58
+
59
+
60
+ title = "Drug Classification"
61
+ description = "Enter the details to correctly identify Drug type?"
62
+ article = "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."
63
+
64
+
65
+ gr.Interface(
66
+ fn=predict_drug,
67
+ inputs=inputs,
68
+ outputs=outputs,
69
+ examples=examples,
70
+ title=title,
71
+ description=description,
72
+ article=article,
73
+ theme=gr.themes.Soft(),
74
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ scikit-learn
2
+ skops