AlexandreL2024 commited on
Commit
eefddd9
Β·
verified Β·
1 Parent(s): 57d05dd

Sync App files

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