Spaces:
Build error
Build error
updated feature inputs and chart..
Browse files
app.py
CHANGED
@@ -1,82 +1,93 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
[45, 0, 0, 0, 0.2],
|
12 |
-
[70, 1, 0, 1, 0.8],
|
13 |
-
[55, 0, 1, 0, 0.6],
|
14 |
-
[50, 1, 1, 1, 0.7]
|
15 |
-
])
|
16 |
|
17 |
-
|
18 |
-
sex_options = ['Male', 'Female']
|
19 |
-
smoking_options = ['No', 'Yes']
|
20 |
-
treatment_options = ['No', 'Yes']
|
21 |
-
chemo_options = ['No', 'Yes']
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
.
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
}
|
58 |
-
.doctor-img {
|
59 |
-
height: auto;
|
60 |
-
width: auto;
|
61 |
-
max-width: 100%;
|
62 |
-
max-height: 100%;
|
63 |
-
}
|
64 |
-
"""
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
]
|
71 |
|
72 |
-
|
73 |
-
fn=predict_cancer,
|
74 |
-
inputs=inputs,
|
75 |
-
outputs=outputs,
|
76 |
-
title='Cancer Predictor',
|
77 |
-
description='Predicts the risk of survival in cancer patients.\nChoose the input values and the prediction will be displayed automatically.',
|
78 |
-
sidebar=sidebar,
|
79 |
-
css=css
|
80 |
-
)
|
81 |
-
|
82 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.graph_objects as go
|
4 |
|
5 |
+
data = {
|
6 |
+
'years_after_diagnosis': [5, 8, 7, 7, 8, 7, 5, 6, 7, 5, 6, 4, 3, 4, 5, 8, 5],
|
7 |
+
'age_at_diagnosis': [54, 41, 65, 85, 60, 66, 61, 50, 77, 64, 55, 52, 60, 51, 45, 54, 48],
|
8 |
+
'stage level': [6, 6, 5, 5, 10, 8, 6, 7, 8, 8, 3, 6, 3, 8, 6, 8, 6],
|
9 |
+
'status': [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0]
|
10 |
+
}
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
df = pd.DataFrame(data)
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
def plot_probability_chart(years_after_diagnosis, age_at_diagnosis, stage_level, chemotherapy, brachtherapy,
|
15 |
+
chemoradiation, radiotherapy, radiation, menopause, MENO_post, HISTOLOGY, CM_1, CM_2, CM_3, Status):
|
16 |
+
match = df.loc[
|
17 |
+
(df['years_after_diagnosis'] == years_after_diagnosis) &
|
18 |
+
(df['age_at_diagnosis'] == age_at_diagnosis) &
|
19 |
+
(df['stage level'] == stage_level)
|
20 |
+
]
|
21 |
+
|
22 |
+
if len(match) == 0:
|
23 |
+
probability_alive = 0.5
|
24 |
+
probability_dead = 0.5
|
25 |
+
label = ["No matching record", "No matching record"]
|
26 |
+
else:
|
27 |
+
status = match.iloc[0]['status']
|
28 |
+
label = ["Alive", "Dead"]
|
29 |
+
|
30 |
+
if status == 0:
|
31 |
+
probability_alive = 0.2
|
32 |
+
probability_dead = 0.8
|
33 |
+
else:
|
34 |
+
probability_alive = 0.7
|
35 |
+
probability_dead = 0.3
|
36 |
|
37 |
+
fig = go.Figure(
|
38 |
+
go.Bar(
|
39 |
+
x=label,
|
40 |
+
y=[probability_alive, probability_dead]
|
41 |
+
)
|
42 |
+
)
|
43 |
+
fig.update_layout(
|
44 |
+
title="Survival Probability Chart",
|
45 |
+
xaxis_title="Status",
|
46 |
+
yaxis_title="Probability",
|
47 |
+
)
|
48 |
+
return fig
|
49 |
+
|
50 |
+
if len(match) == 0:
|
51 |
+
return "No matching patient record found"
|
52 |
+
|
53 |
+
status = match.iloc[0]['status']
|
54 |
+
label = ["Alive", "Dead"]
|
55 |
+
if status == 0:
|
56 |
+
probability_alive = 0.2
|
57 |
+
probability_dead = 0.8
|
58 |
+
else:
|
59 |
+
probability_alive = 0.7
|
60 |
+
probability_dead = 0.3
|
61 |
|
62 |
+
fig = go.Figure(
|
63 |
+
go.Bar(
|
64 |
+
x=label,
|
65 |
+
y=[probability_alive, probability_dead]
|
66 |
+
)
|
67 |
+
)
|
68 |
+
fig.update_layout(
|
69 |
+
title="Survival Probability Chart",
|
70 |
+
xaxis_title="Status",
|
71 |
+
yaxis_title="Probability",
|
72 |
+
)
|
73 |
+
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
inputs = [
|
76 |
+
gr.inputs.Slider(minimum=0, maximum=10, step=1, default=5, label='years_after_diagnosis'),
|
77 |
+
gr.inputs.Slider(minimum=0, maximum=100, step=1, default=54, label='age_at_diagnosis'),
|
78 |
+
gr.inputs.Slider(minimum=0, maximum=10, step=1, default=6, label='stage level'),
|
79 |
+
gr.inputs.Checkbox(label='chemotherapy'),
|
80 |
+
gr.inputs.Checkbox(label='brachtherapy'),
|
81 |
+
gr.inputs.Checkbox(label='chemoradiation'),
|
82 |
+
gr.inputs.Checkbox(label='radiotherapy'),
|
83 |
+
gr.inputs.Checkbox(label='radiation'),
|
84 |
+
gr.inputs.Slider(minimum=0, maximum=30, step=1, default=0, label='menopause'),
|
85 |
+
gr.inputs.Slider(minimum=0, maximum=30, step=1, default=0, label='MENO_post'),
|
86 |
+
gr.inputs.Slider(minimum=0, maximum=2, step=1, default=2, label='HISTOLOGY'),
|
87 |
+
gr.inputs.Checkbox(label='CM_1'),
|
88 |
+
gr.inputs.Checkbox(label='CM_2'),
|
89 |
+
gr.inputs.Checkbox(label='CM_3'),
|
90 |
+
gr.inputs.Radio(["Alive", "Dead"], label="Status")
|
91 |
]
|
92 |
|
93 |
+
gr.Interface(fn=plot_probability_chart, inputs=inputs, outputs="plot").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|