Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- SVR_model.joblib +3 -0
- app.py +100 -0
- best_DecisionTreeRegressor_model.joblib +3 -0
- best_DeepLearning_model.h5 +3 -0
- column_transformer.joblib +3 -0
- label_encoder.joblib +3 -0
SVR_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:04f78b940f119368c8d63d13453c7bd677071249ac85714f5efd4d8e6e645b65
|
3 |
+
size 2099780
|
app.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""app.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1oJP09Coya1D16dQ_7fpVGlbuLnCWxHTN
|
8 |
+
"""
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
import joblib
|
12 |
+
import numpy as np
|
13 |
+
from tensorflow.keras.models import load_model
|
14 |
+
|
15 |
+
# Load models
|
16 |
+
svr_model = joblib.load('SVR_model.joblib')
|
17 |
+
rf_model = joblib.load('RandomForestRegressor_model.joblib')
|
18 |
+
dt_model = joblib.load('best_DecisionTreeRegressor_model.joblib')
|
19 |
+
dl_model = load_model('best_DeepLearning_model.h5')
|
20 |
+
|
21 |
+
# Load preprocessing objects
|
22 |
+
label_encoder = joblib.load('label_encoder.joblib')
|
23 |
+
column_transformer = joblib.load('column_transformer.joblib')
|
24 |
+
|
25 |
+
def predict_warfarin_dose(gender, race, age, height, weight, diabetes,
|
26 |
+
simvastatin, amiodarone, inr_reported,
|
27 |
+
cyp2c9, vkorc1, model_choice):
|
28 |
+
try:
|
29 |
+
# Encode Age
|
30 |
+
age_encoded = label_encoder.transform([age])
|
31 |
+
|
32 |
+
# Create input list
|
33 |
+
inputs = [
|
34 |
+
str(gender),
|
35 |
+
str(race),
|
36 |
+
str(age),
|
37 |
+
float(height) if height is not None else 0.0,
|
38 |
+
float(weight) if weight is not None else 0.0,
|
39 |
+
float(diabetes),
|
40 |
+
float(simvastatin),
|
41 |
+
float(amiodarone),
|
42 |
+
float(inr_reported) if inr_reported is not None else 0.0,
|
43 |
+
str(cyp2c9),
|
44 |
+
str(vkorc1)
|
45 |
+
]
|
46 |
+
|
47 |
+
# Transform inputs
|
48 |
+
inputs_transformed = column_transformer.transform([inputs])
|
49 |
+
inputs_transformed[0][-7] = age_encoded[0]
|
50 |
+
input_data = np.array(inputs_transformed, dtype=np.float32)
|
51 |
+
|
52 |
+
# Make prediction based on model choice
|
53 |
+
if model_choice == 'Deep Learning':
|
54 |
+
prediction = dl_model.predict(input_data)[0][0]
|
55 |
+
elif model_choice == 'Support Vector Regression':
|
56 |
+
prediction = svr_model.predict(input_data)[0]
|
57 |
+
elif model_choice == 'Random Forest':
|
58 |
+
prediction = rf_model.predict(input_data)[0]
|
59 |
+
else:
|
60 |
+
prediction = dt_model.predict(input_data)[0]
|
61 |
+
|
62 |
+
return f"Predicted Warfarin Dose: {prediction:.2f} mg/week"
|
63 |
+
|
64 |
+
except Exception as e:
|
65 |
+
return f"Error in prediction: {str(e)}"
|
66 |
+
|
67 |
+
# Create the Gradio interface
|
68 |
+
iface = gr.Interface(
|
69 |
+
fn=predict_warfarin_dose,
|
70 |
+
inputs=[
|
71 |
+
gr.Radio(["male", "female"], label="Gender"),
|
72 |
+
gr.Dropdown(["Asian", "Black", "White", "Unknown", "Mixed or Missing"], label="Race"),
|
73 |
+
gr.Dropdown(["0-9", "10-19", "20-29", "30-39", "40-49", "50-59", "60-69",
|
74 |
+
"70-79", "80-89", "90+"], label="Age"),
|
75 |
+
gr.Number(label="Height (cm)"),
|
76 |
+
gr.Number(label="Weight (kg)"),
|
77 |
+
gr.Radio([0.0, 1.0], label="Diabetes"),
|
78 |
+
gr.Radio([0.0, 1.0], label="Simvastatin (Zocor)"),
|
79 |
+
gr.Radio([0.0, 1.0], label="Amiodarone (Cordarone)"),
|
80 |
+
gr.Number(label="INR on Reported Therapeutic Dose of Warfarin"),
|
81 |
+
gr.Dropdown(["*1/*1", "*1/*2", "*1/*3", "*2/*2", "*2/*3", "*3/*3"],
|
82 |
+
label="Cyp2C9 genotypes"),
|
83 |
+
gr.Radio(["A/A", "A/G", "G/G"], label="VKORC1 genotypes"),
|
84 |
+
gr.Dropdown(['Decision Tree', 'Support Vector Regression',
|
85 |
+
'Random Forest', 'Deep Learning'], label="Model Selection")
|
86 |
+
],
|
87 |
+
outputs=gr.Textbox(label="Prediction Result"),
|
88 |
+
title="Warfarin Dosage Prediction System",
|
89 |
+
description="""This system predicts the optimal warfarin dosage based on patient characteristics.
|
90 |
+
Enter the required information below and select a model for prediction.""",
|
91 |
+
examples=[
|
92 |
+
["male", "Asian", "50-59", 170, 70, 0.0, 0.0, 0.0, 2.5, "*1/*1", "A/G", "Random Forest"],
|
93 |
+
["female", "White", "60-69", 165, 65, 1.0, 1.0, 0.0, 2.8, "*1/*2", "G/G", "Deep Learning"]
|
94 |
+
],
|
95 |
+
theme="default"
|
96 |
+
)
|
97 |
+
|
98 |
+
# Launch the interface
|
99 |
+
if __name__ == "__main__":
|
100 |
+
iface.launch()
|
best_DecisionTreeRegressor_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d64a6f6fe40203c967075341ee946923648853e2cc88da6e99e6b518f351f046
|
3 |
+
size 165137
|
best_DeepLearning_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4937dd6061b79dac101bd26ea27b5b2bd1216ace8a3c8da7244df95a8904e392
|
3 |
+
size 102568
|
column_transformer.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b4d987360470bb30eaa77602946506da66261028184ca164d1d333debe7d900
|
3 |
+
size 4719
|
label_encoder.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5c20f850cce07c65075ca30ae733aa76faa2068edd9e1d10e6a0d969fb40f88e
|
3 |
+
size 640
|