Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- app.py +91 -0
- requirements.txt +4 -0
- weights/rf_with_10_roc-8502.pkl +3 -0
- weights/rf_with_3_roc-7596.pkl +3 -0
- weights/rf_with_5_roc-8557.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# 모델 로드
|
| 6 |
+
with open("weights/rf_with_3_roc-7596.pkl", "rb") as f:
|
| 7 |
+
model_3 = pickle.load(f)
|
| 8 |
+
|
| 9 |
+
with open("weights/rf_with_5_roc-8557.pkl", "rb") as f:
|
| 10 |
+
model_5 = pickle.load(f)
|
| 11 |
+
|
| 12 |
+
with open("weights/rf_with_10_roc-8502.pkl", "rb") as f:
|
| 13 |
+
model_10 = pickle.load(f)
|
| 14 |
+
|
| 15 |
+
def predict(model_choice, *features):
|
| 16 |
+
if model_choice == "3 Features Model":
|
| 17 |
+
model = model_3
|
| 18 |
+
features = np.array(features[:3]).reshape(1, -1)
|
| 19 |
+
elif model_choice == "5 Features Model":
|
| 20 |
+
model = model_5
|
| 21 |
+
features = np.array(features[:5]).reshape(1, -1)
|
| 22 |
+
else:
|
| 23 |
+
model = model_10
|
| 24 |
+
features = np.array(features[:10]).reshape(1, -1)
|
| 25 |
+
|
| 26 |
+
probs = model.predict_proba(features)[0]
|
| 27 |
+
pred_class = np.argmax(probs)
|
| 28 |
+
return {"Healthy Probability": probs[0], "Moderate Probability": probs[1], "Severe Probability": probs[2], "Predicted Class": ["Healthy", "Moderate", "Severe"][pred_class]}
|
| 29 |
+
|
| 30 |
+
def update_inputs(model_choice):
|
| 31 |
+
if model_choice == "3 Features Model":
|
| 32 |
+
return [gr.update(visible=True)] * 3 + [gr.update(visible=False)] * 7
|
| 33 |
+
elif model_choice == "5 Features Model":
|
| 34 |
+
return [gr.update(visible=True)] * 5 + [gr.update(visible=False)] * 5
|
| 35 |
+
else:
|
| 36 |
+
return [gr.update(visible=True)] * 10
|
| 37 |
+
|
| 38 |
+
# 3 환자 데이터
|
| 39 |
+
patient_data = [
|
| 40 |
+
[3796, 1935, 1148, 2193, 650, 1091, 243, 10135, 260, 23640], # 환자 1
|
| 41 |
+
[626, 515, 185, 9150, 1863, 587, 2196, 7021, 1149, 5980], # 환자 2
|
| 42 |
+
[0, 328, 0, 258, 123, 116, 0, 423, 1145, 4916] # 환자 3
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
def fill_patient_data(model_choice, patient_index):
|
| 46 |
+
data = patient_data[patient_index]
|
| 47 |
+
if model_choice == "3 Features Model":
|
| 48 |
+
return data[:3] + [None] * 7
|
| 49 |
+
elif model_choice == "5 Features Model":
|
| 50 |
+
return data[:5] + [None] * 5
|
| 51 |
+
else:
|
| 52 |
+
return data[:10]
|
| 53 |
+
|
| 54 |
+
def clear_inputs():
|
| 55 |
+
return [None] * 10
|
| 56 |
+
|
| 57 |
+
features = [
|
| 58 |
+
"CD8+ T Cell (EM CD27hi)",
|
| 59 |
+
"CD8+ T Cell (EMRA CD57hi)",
|
| 60 |
+
"gd T Cell",
|
| 61 |
+
"Conventional DC",
|
| 62 |
+
"NK Cell (CD56Low CD16hi CD571ow)",
|
| 63 |
+
"NK Cell (CD56low CD1Ghi CDS7hi)",
|
| 64 |
+
"CD8+ T Cell (EMRA CDS7low)",
|
| 65 |
+
"Monocytes (CD14+ CD16+)",
|
| 66 |
+
"B Cell (Plasmablast)",
|
| 67 |
+
"CD4+ T Cell (Naive)"
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# Gradio UI 구성
|
| 72 |
+
with gr.Blocks() as demo:
|
| 73 |
+
gr.Markdown("## COVID-19 Severity Classification App")
|
| 74 |
+
with gr.Row():
|
| 75 |
+
with gr.Column(scale=1):
|
| 76 |
+
model_choice = gr.Radio(["3 Features Model", "5 Features Model", "10 Features Model"], label="Choose Model", value="5 Features Model")
|
| 77 |
+
inputs = [gr.Number(label=features[i], visible=(i < 5)) for i in range(10)]
|
| 78 |
+
with gr.Row():
|
| 79 |
+
gr.Button("Healthy").click(fill_patient_data, inputs=[model_choice, gr.State(0)], outputs=inputs)
|
| 80 |
+
gr.Button("Moderate").click(fill_patient_data, inputs=[model_choice, gr.State(1)], outputs=inputs)
|
| 81 |
+
gr.Button("Severe").click(fill_patient_data, inputs=[model_choice, gr.State(2)], outputs=inputs)
|
| 82 |
+
run_button = gr.Button("Run Prediction")
|
| 83 |
+
with gr.Column(scale=1):
|
| 84 |
+
output = gr.JSON(label="Prediction Output")
|
| 85 |
+
gr.Button("Clear").click(clear_inputs, outputs=inputs)
|
| 86 |
+
|
| 87 |
+
model_choice.change(update_inputs, inputs=[model_choice], outputs=inputs)
|
| 88 |
+
run_button.click(predict, inputs=[model_choice] + inputs, outputs=output)
|
| 89 |
+
|
| 90 |
+
# 앱 실행
|
| 91 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
numpy
|
| 3 |
+
scikit-learn
|
| 4 |
+
pickle-mixin
|
weights/rf_with_10_roc-8502.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8a019e21a0c7a69d928cd8083a27905ebf0082f89b640544668e63afe1f1bd80
|
| 3 |
+
size 337191
|
weights/rf_with_3_roc-7596.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cc0ae55ebb5ddf3041e768bff175751e3b135d9670f8dd5dc9485cbf23ff974a
|
| 3 |
+
size 262820
|
weights/rf_with_5_roc-8557.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1141afebc705da4d713ae317ad33b1d3eab1d6423d0f89ea4476864651b490bb
|
| 3 |
+
size 271925
|