milotix commited on
Commit
1d1fcb1
·
verified ·
1 Parent(s): 0fb493f

Sync App files

Browse files
Files changed (3) hide show
  1. README.md +7 -9
  2. drug_app.py +66 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,13 +1,11 @@
1
  ---
2
- title: DrugClassification
3
- emoji: 🦀
4
- colorFrom: gray
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 6.0.1
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: 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,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import skops.io as sio
3
+
4
+ # Get the list of ALL types found in the file
5
+ all_untrusted_types = sio.get_untrusted_types(file="./model/drug_pipeline.skops")
6
+
7
+ # Print and review the list (e.g., ['numpy.dtype', 'sklearn.pipeline.Pipeline', ...])
8
+ # print(all_untrusted_types)
9
+
10
+ # Load the model, passing the complete list as the trusted argument
11
+ pipe = sio.load(
12
+ "./model/drug_pipeline.skops",
13
+ trusted=all_untrusted_types
14
+ )
15
+
16
+ def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):
17
+ """Predict drugs based on patient features.
18
+
19
+ Args:
20
+ age (int): Age of patient
21
+ sex (str): Sex of patient
22
+ blood_pressure (str): Blood pressure level
23
+ cholesterol (str): Cholesterol level
24
+ na_to_k_ratio (float): Ratio of sodium to potassium in blood
25
+
26
+ Returns:
27
+ str: Predicted drug label
28
+ """
29
+ features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
30
+ predicted_drug = pipe.predict([features])[0]
31
+
32
+ label = f"Predicted Drug: {predicted_drug}"
33
+ return label
34
+
35
+
36
+ inputs = [
37
+ gr.Slider(15, 74, step=1, label="Age"),
38
+ gr.Radio(["M", "F"], label="Sex"),
39
+ gr.Radio(["HIGH", "LOW", "NORMAL"], label="Blood Pressure"),
40
+ gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
41
+ gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
42
+ ]
43
+ outputs = [gr.Label(num_top_classes=5)]
44
+
45
+ examples = [
46
+ [30, "M", "HIGH", "NORMAL", 15.4],
47
+ [35, "F", "LOW", "NORMAL", 8],
48
+ [50, "M", "HIGH", "HIGH", 34],
49
+ ]
50
+
51
+
52
+ title = "Drug Classification"
53
+ description = "Enter the details to correctly identify Drug type?"
54
+ article = "Automate training, evaluation, and deployment of models to Hugging Face using GitHub Actions."
55
+
56
+
57
+ gr.Interface(
58
+ fn=predict_drug,
59
+ inputs=inputs,
60
+ outputs=outputs,
61
+ examples=examples,
62
+ title=title,
63
+ description=description,
64
+ article=article,
65
+ # theme=gr.themes.Soft(),
66
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ scikit-learn
2
+ skops