SaiThapan commited on
Commit
650ca08
Β·
verified Β·
1 Parent(s): 2eb843f

Sync App files

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