Spaces:
Sleeping
Sleeping
Sync App files
Browse files- drug_app.py +10 -7
drug_app.py
CHANGED
|
@@ -27,12 +27,15 @@ def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio):
|
|
| 27 |
str: Predicted drug label
|
| 28 |
"""
|
| 29 |
features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
inputs = [
|
|
@@ -42,7 +45,7 @@ inputs = [
|
|
| 42 |
gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
|
| 43 |
gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
|
| 44 |
]
|
| 45 |
-
outputs =
|
| 46 |
|
| 47 |
examples = [
|
| 48 |
[30, "M", "HIGH", "NORMAL", 15.4],
|
|
|
|
| 27 |
str: Predicted drug label
|
| 28 |
"""
|
| 29 |
features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
|
| 30 |
+
try:
|
| 31 |
+
probabilities = pipe.predict_proba([features])[0]
|
| 32 |
+
return {
|
| 33 |
+
str(label): float(prob)
|
| 34 |
+
for label, prob in zip(pipe.classes_, probabilities)
|
| 35 |
+
}
|
| 36 |
+
except Exception:
|
| 37 |
+
predicted_drug = pipe.predict([features])[0]
|
| 38 |
+
return str(predicted_drug)
|
| 39 |
|
| 40 |
|
| 41 |
inputs = [
|
|
|
|
| 45 |
gr.Radio(["HIGH", "NORMAL"], label="Cholesterol"),
|
| 46 |
gr.Slider(6.2, 38.2, step=0.1, label="Na_to_K"),
|
| 47 |
]
|
| 48 |
+
outputs = gr.Label(num_top_classes=5)
|
| 49 |
|
| 50 |
examples = [
|
| 51 |
[30, "M", "HIGH", "NORMAL", 15.4],
|