arifulamin commited on
Commit
5e163fa
·
verified ·
1 Parent(s): 6360eb9

Sync App files

Browse files
Files changed (3) hide show
  1. README.md +5 -9
  2. app.py +85 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,9 @@
1
- ---
2
  title: Drug Classification
3
- emoji: 👀
4
- colorFrom: red
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 5.15.0
8
  app_file: app.py
9
  pinned: false
10
- license: cc
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  title: Drug Classification
2
+ emoji: 📉
3
+ colorFrom: purple
4
+ colorTo: green
5
  sdk: gradio
6
+ sdk_version: 5.14.0
7
  app_file: app.py
8
  pinned: false
9
+ license: apache-2.0
 
 
 
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import skops.io as sio
4
+ import warnings
5
+ from sklearn.exceptions import InconsistentVersionWarning
6
+
7
+ import os
8
+ import subprocess
9
+
10
+ try:
11
+ import skops.io as sio
12
+ except ModuleNotFoundError:
13
+ print("skops not found. Installing now...")
14
+ subprocess.run(["pip", "install", "skops"], check=True)
15
+ import skops.io as sio # Retry import
16
+
17
+ # Suppress the version warnings
18
+ warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
19
+
20
+ # Explicitly specify trusted types
21
+ trusted_types = [
22
+ "sklearn.pipeline.Pipeline",
23
+ "sklearn.preprocessing.OneHotEncoder",
24
+ "sklearn.preprocessing.StandardScaler",
25
+ "sklearn.compose.ColumnTransformer",
26
+ "sklearn.preprocessing.OrdinalEncoder",
27
+ "sklearn.impute.SimpleImputer",
28
+ "sklearn.tree.DecisionTreeClassifier",
29
+ "sklearn.ensemble.RandomForestClassifier",
30
+ "numpy.dtype",
31
+ ]
32
+ pipe = sio.load("./Model/drug_pipeline.skops", trusted=trusted_types)
33
+
34
+
35
+ def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):
36
+ """Predict drugs based on patient features.
37
+
38
+ Args:
39
+ age (int): Age of patient
40
+ sex (str): Sex of patient
41
+ blood_pressure (str): Blood pressure level
42
+ cholesterol (str): Cholesterol level
43
+ na_to_k_ratio (float): Ratio of sodium to potassium in blood
44
+
45
+ Returns:
46
+ str: Predicted drug label
47
+ """
48
+ features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
49
+ predicted_drug = pipe.predict([features])[0]
50
+
51
+ label = f"Predicted Drug: {predicted_drug}"
52
+ return label
53
+
54
+
55
+ inputs = [
56
+ gr.Slider(15, 74, step=1, label="Age"),
57
+ gr.Radio(["M", "F"], label="Sex"),
58
+ gr.Radio(["HIGH", "LOW", "NORMAL"], label="Blood Pressure"),
59
+ gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
60
+ gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
61
+ ]
62
+ outputs = [gr.Label(num_top_classes=5)]
63
+
64
+ examples = [
65
+ [30, "M", "HIGH", "NORMAL", 15.4],
66
+ [35, "F", "LOW", "NORMAL", 8],
67
+ [50, "M", "HIGH", "HIGH", 34],
68
+ ]
69
+
70
+
71
+ title = "Drug Classification"
72
+ description = "Enter the details to correctly identify Drug type?"
73
+ 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."
74
+
75
+
76
+ gr.Interface(
77
+ fn=predict_drug,
78
+ inputs=inputs,
79
+ outputs=outputs,
80
+ examples=examples,
81
+ title=title,
82
+ description=description,
83
+ article=article,
84
+ theme=gr.themes.Soft(),
85
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ scikit-learn
2
+ gradio
3
+ skops