Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,100 +0,0 @@
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|