Spaces:
Build error
Build error
Upload 2 files
Browse files- .gitattributes +1 -0
- caner_prediction.py +82 -0
- doctor.png +3 -0
.gitattributes
CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
doctor.png filter=lfs diff=lfs merge=lfs -text
|
caner_prediction.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import urllib.request
|
4 |
+
|
5 |
+
# Downloading the image and saving it in the local folder
|
6 |
+
# urllib.request.urlretrieve('https://cdn.discordapp.com/attachments/682736875483430985/1089711182094553108/Dopeshott_young_black_femal_doctor_19e26be2-6801-4aed-b481-793b1e77a984.png', 'doctor.png')
|
7 |
+
|
8 |
+
# Dummy data
|
9 |
+
data = np.array([
|
10 |
+
[65, 1, 1, 1, 0.5],
|
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 |
+
features = ['Age', 'Sex', 'Smoking', 'Treatment', 'Chemotherapy']
|
18 |
+
sex_options = ['Male', 'Female']
|
19 |
+
smoking_options = ['No', 'Yes']
|
20 |
+
treatment_options = ['No', 'Yes']
|
21 |
+
chemo_options = ['No', 'Yes']
|
22 |
+
|
23 |
+
# Function to predict cancer
|
24 |
+
def predict_cancer(age, sex, smoking, treatment, chemotherapy):
|
25 |
+
# Format input
|
26 |
+
sex = 0 if sex == 'Male' else 1
|
27 |
+
smoking = 0 if smoking == 'No' else 1
|
28 |
+
treatment = 0 if treatment == 'No' else 1
|
29 |
+
chemotherapy = 0 if chemotherapy == 'No' else 1
|
30 |
+
input_data = np.array([[age, sex, smoking, treatment, chemotherapy]])
|
31 |
+
# Dummy prediction
|
32 |
+
prob_alive = np.random.choice([0.8, 0.7, 0.65, 0.548, 0.78])
|
33 |
+
prediction = 'Alive' if prob_alive >= 0.5 else 'Dead'
|
34 |
+
return f'{prediction} with a survival probability of {prob_alive:.3f}'
|
35 |
+
|
36 |
+
# Interface
|
37 |
+
age_slider = gr.inputs.Slider(minimum=20, maximum=90, step=1, label='Age')
|
38 |
+
sex_dropdown = gr.inputs.Dropdown(choices=sex_options, label='Sex')
|
39 |
+
smoking_dropdown = gr.inputs.Dropdown(choices=smoking_options, label='Smoking')
|
40 |
+
treatment_dropdown = gr.inputs.Dropdown(choices=treatment_options, label='Treatment')
|
41 |
+
chemo_dropdown = gr.inputs.Dropdown(choices=chemo_options, label='Chemotherapy')
|
42 |
+
inputs = [age_slider, sex_dropdown, smoking_dropdown, treatment_dropdown, chemo_dropdown]
|
43 |
+
outputs = gr.outputs.Textbox(label='Prediction')
|
44 |
+
|
45 |
+
css = """
|
46 |
+
.sidebar-content {
|
47 |
+
padding: 20px;
|
48 |
+
background-color: #f5f5f5;
|
49 |
+
box-shadow: 1px 1px 10px #ccc;
|
50 |
+
margin-bottom: 20px;
|
51 |
+
border-radius: 10px;
|
52 |
+
}
|
53 |
+
.doctor-img-container {
|
54 |
+
display: flex;
|
55 |
+
align-items: center;
|
56 |
+
justify-content: center;
|
57 |
+
}
|
58 |
+
.doctor-img {
|
59 |
+
height: auto;
|
60 |
+
width: auto;
|
61 |
+
max-width: 100%;
|
62 |
+
max-height: 100%;
|
63 |
+
}
|
64 |
+
"""
|
65 |
+
|
66 |
+
sidebar = [
|
67 |
+
# Adding image of a doctor to the sidebar
|
68 |
+
'<div class="doctor-img-container"><img class="doctor-img" src="doctor.png" alt="A medical doctor"></div>',
|
69 |
+
'This is a cancer prediction app',
|
70 |
+
]
|
71 |
+
|
72 |
+
iface = gr.Interface(
|
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()
|
doctor.png
ADDED
![]() |
Git LFS Details
|