Gabrielokiri commited on
Commit
b074f32
Β·
verified Β·
1 Parent(s): acc6c81

Sync App files

Browse files
Files changed (3) hide show
  1. README.md +6 -9
  2. drug_app.py +74 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,14 +1,11 @@
1
  ---
2
  title: Drug Classification
3
- emoji: πŸ‘
4
- colorFrom: blue
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 5.11.0
8
- app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
- short_description: Drug-Classification
12
- ---
13
-
14
- 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,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