Spaces:
Build error
Build error
File size: 3,163 Bytes
4be7b9f 4fdb56d 4be7b9f 4fdb56d 4be7b9f 4fdb56d 4be7b9f 4fdb56d 4be7b9f 4fdb56d 4be7b9f 4fdb56d 4be7b9f 4fdb56d 4be7b9f 4fdb56d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import gradio as gr
import pandas as pd
import plotly.graph_objects as go
data = {
'years_after_diagnosis': [5, 8, 7, 7, 8, 7, 5, 6, 7, 5, 6, 4, 3, 4, 5, 8, 5],
'age_at_diagnosis': [54, 41, 65, 85, 60, 66, 61, 50, 77, 64, 55, 52, 60, 51, 45, 54, 48],
'stage level': [6, 6, 5, 5, 10, 8, 6, 7, 8, 8, 3, 6, 3, 8, 6, 8, 6],
'status': [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0]
}
df = pd.DataFrame(data)
def plot_probability_chart(years_after_diagnosis, age_at_diagnosis, stage_level, chemotherapy, brachtherapy,
chemoradiation, radiotherapy, radiation, menopause, MENO_post, HISTOLOGY, CM_1, CM_2, CM_3, Status):
match = df.loc[
(df['years_after_diagnosis'] == years_after_diagnosis) &
(df['age_at_diagnosis'] == age_at_diagnosis) &
(df['stage level'] == stage_level)
]
if len(match) == 0:
probability_alive = 0.5
probability_dead = 0.5
label = ["No matching record", "No matching record"]
else:
status = match.iloc[0]['status']
label = ["Alive", "Dead"]
if status == 0:
probability_alive = 0.2
probability_dead = 0.8
else:
probability_alive = 0.7
probability_dead = 0.3
fig = go.Figure(
go.Bar(
x=label,
y=[probability_alive, probability_dead]
)
)
fig.update_layout(
title="Survival Probability Chart",
xaxis_title="Status",
yaxis_title="Probability",
)
return fig
if len(match) == 0:
return "No matching patient record found"
status = match.iloc[0]['status']
label = ["Alive", "Dead"]
if status == 0:
probability_alive = 0.2
probability_dead = 0.8
else:
probability_alive = 0.7
probability_dead = 0.3
fig = go.Figure(
go.Bar(
x=label,
y=[probability_alive, probability_dead]
)
)
fig.update_layout(
title="Survival Probability Chart",
xaxis_title="Status",
yaxis_title="Probability",
)
return fig
inputs = [
gr.inputs.Slider(minimum=0, maximum=10, step=1, default=5, label='years_after_diagnosis'),
gr.inputs.Slider(minimum=0, maximum=100, step=1, default=54, label='age_at_diagnosis'),
gr.inputs.Slider(minimum=0, maximum=10, step=1, default=6, label='stage level'),
gr.inputs.Checkbox(label='chemotherapy'),
gr.inputs.Checkbox(label='brachtherapy'),
gr.inputs.Checkbox(label='chemoradiation'),
gr.inputs.Checkbox(label='radiotherapy'),
gr.inputs.Checkbox(label='radiation'),
gr.inputs.Slider(minimum=0, maximum=30, step=1, default=0, label='menopause'),
gr.inputs.Slider(minimum=0, maximum=30, step=1, default=0, label='MENO_post'),
gr.inputs.Slider(minimum=0, maximum=2, step=1, default=2, label='HISTOLOGY'),
gr.inputs.Checkbox(label='CM_1'),
gr.inputs.Checkbox(label='CM_2'),
gr.inputs.Checkbox(label='CM_3'),
gr.inputs.Radio(["Alive", "Dead"], label="Status")
]
gr.Interface(fn=plot_probability_chart, inputs=inputs, outputs="plot").launch() |