mariemerenc commited on
Commit
f3e3166
·
verified ·
1 Parent(s): 5252999

Sync App files

Browse files
Files changed (3) hide show
  1. README.md +15 -6
  2. drug_app.py +58 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,21 @@
1
  ---
2
  title: Drug Classification
3
- emoji: 🐨
4
- colorFrom: purple
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.3.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- 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
  ---
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,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import skops.io as sio
3
+
4
+ unknown_types = sio.get_untrusted_types(file="./Model/drug_pipeline.skops")
5
+ pipe = sio.load("./Model/drug_pipeline.skops", trusted=unknown_types)
6
+
7
+
8
+ def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):
9
+ """Predict drugs based on patient features.
10
+
11
+ Args:
12
+ age (int): Age of patient
13
+ sex (str): Sex of patient
14
+ blood_pressure (str): Blood pressure level
15
+ cholesterol (str): Cholesterol level
16
+ na_to_k_ratio (float): Ratio of sodium to potassium in blood
17
+
18
+ Returns:
19
+ str: Predicted drug label
20
+ """
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 label
26
+
27
+
28
+ inputs = [
29
+ gr.Slider(15, 74, step=1, label="Age"),
30
+ gr.Radio(["M", "F"], label="Sex"),
31
+ gr.Radio(["HIGH", "LOW", "NORMAL"], label="Blood Pressure"),
32
+ gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
33
+ gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
34
+ ]
35
+ outputs = [gr.Label(num_top_classes=5)]
36
+
37
+ examples = [
38
+ [30, "M", "HIGH", "NORMAL", 15.4],
39
+ [35, "F", "LOW", "NORMAL", 8],
40
+ [50, "M", "HIGH", "HIGH", 34],
41
+ ]
42
+
43
+
44
+ title = "Drug Classification"
45
+ description = "Enter the details to correctly identify Drug type?"
46
+ 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."
47
+
48
+
49
+ gr.Interface(
50
+ fn=predict_drug,
51
+ inputs=inputs,
52
+ outputs=outputs,
53
+ examples=examples,
54
+ title=title,
55
+ description=description,
56
+ article=article,
57
+ theme=gr.themes.Soft(),
58
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ scikit-learn
2
+ skops