Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,74 +11,156 @@ import tensorflow as tf
|
|
| 11 |
from tensorflow.keras.applications import imagenet_utils
|
| 12 |
from tensorflow.keras.utils import img_to_array
|
| 13 |
from tensorflow.keras.models import load_model
|
| 14 |
-
import cv2
|
| 15 |
-
|
| 16 |
import pdfplumber
|
| 17 |
import re
|
| 18 |
from collections import namedtuple
|
| 19 |
-
|
| 20 |
-
#LOADING THE DATA
|
| 21 |
-
results = loading_data()
|
| 22 |
-
|
| 23 |
-
Xtrain = results["Xtrain"]
|
| 24 |
-
Ytrain = results["Ytrain"]
|
| 25 |
-
Xtest_encoded = results["Xtest_encoded"]
|
| 26 |
-
Ytest = results["Ytest"]
|
| 27 |
-
num_col_trans = results["num_col_trans"]
|
| 28 |
-
cat_col_trans = results["cat_col_trans"]
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# POUR VGG16
|
| 32 |
-
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
-
|
| 37 |
-
my_output = gr.Label(label="Resultat de la prédiction",num_top_classes=2)
|
| 38 |
-
output_valeur = gr.outputs.HTML(label="")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
|
|
|
| 54 |
|
|
|
|
| 55 |
|
| 56 |
-
input_file_PDF = gr.File(label='PDF')
|
| 57 |
-
text_output2 = gr.Label(label="Resultat de la prédiction",num_top_classes=3)
|
| 58 |
-
df_ouput = gr.Dataframe(label="Caractéristique du patient",
|
| 59 |
-
headers=["HighBP","HighChol", "CholCheck", "BMI", "Smoker","Stroke","HeartDiseaseorAttack",
|
| 60 |
-
"PhysActivity", "Fruits", "Veggies","HvyAlcoholConsump","AnyHealthcare", "NoDocbcCost", "GenHlth",
|
| 61 |
-
"MentHlth", "PhysHlth", "DiffWalk",
|
| 62 |
-
"Sex", "Age", "Education","Income"],
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
diabtes_PDF_interface = gr.Interface(get_data_inputPDF, inputs=input_file_PDF,
|
| 70 |
-
outputs=[df_ouput,output_valeurs,text_output2]
|
| 71 |
-
)
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
#---------------------------------------------------------------------------------------
|
| 76 |
|
| 77 |
-
demo = gr.TabbedInterface([vgg16_interface, diabtes_PDF_interface], ["Détéction d'une tumeur", "(PDF) Diabétique, prédiabétique ou sain"])
|
| 78 |
|
| 79 |
demo.launch()
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
-
|
| 84 |
-
demo.launch(share=True)
|
|
|
|
| 11 |
from tensorflow.keras.applications import imagenet_utils
|
| 12 |
from tensorflow.keras.utils import img_to_array
|
| 13 |
from tensorflow.keras.models import load_model
|
|
|
|
|
|
|
| 14 |
import pdfplumber
|
| 15 |
import re
|
| 16 |
from collections import namedtuple
|
| 17 |
+
from compress_pickle import dump, load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
+
demo = gr.Blocks(theme="peach")
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
with demo:
|
| 24 |
+
gr.Markdown(
|
| 25 |
+
"""
|
| 26 |
+
<p>
|
| 27 |
+
<center>
|
| 28 |
+
<img src="https://huggingface.co/spaces/cnasa/Tumor_and_Diabetes/resolve/main/softeam.png" alt="Healthcare thechnology doctor image" width="200"/>
|
| 29 |
+
</center>
|
| 30 |
+
</p>
|
| 31 |
|
| 32 |
+
# Machine learning DEMO
|
| 33 |
+
---
|
| 34 |
|
| 35 |
+
""")
|
| 36 |
+
with gr.Tabs():
|
| 37 |
+
with gr.TabItem("Détéction d'une tumeur"):
|
| 38 |
+
|
| 39 |
+
my_input = gr.inputs.Image(shape=(224,224))
|
| 40 |
+
|
| 41 |
|
| 42 |
+
vgg16_button = gr.Button("Soumettre")
|
| 43 |
+
|
| 44 |
+
output_html = gr.outputs.HTML(label="")
|
| 45 |
+
# my_output = gr.Label(label="Resultat de la prédiction",num_top_classes=2)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
with gr.TabItem("(PDF) Diabétique, prédiabétique ou sain"):
|
| 51 |
+
# POUR DIABETES FICHIER PDF
|
| 52 |
+
with gr.Row():
|
| 53 |
+
input_file_PDF = gr.File(label='PDF')
|
| 54 |
+
PDF_diabete_button = gr.Button("Soumettre")
|
| 55 |
+
df_ouput = gr.Dataframe(label="Caractéristique du patient",
|
| 56 |
+
headers=["HighBP","HighChol", "CholCheck", "BMI", "Smoker","Stroke","HeartDiseaseorAttack","PhysActivity","Fruits","Veggies","HvyAlcoholConsump","AnyHealthcare", "NoDocbcCost", "GenHlth","MentHlth", "PhysHlth", "DiffWalk","Sex", "Age", "Education","Income"],
|
| 57 |
+
row_count=1,col_count=(21),max_rows=2,overflow_row_behaviour='paginate')
|
| 58 |
|
| 59 |
+
|
| 60 |
|
| 61 |
+
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
|
| 65 |
+
output_html1 = gr.outputs.HTML(label="")
|
| 66 |
+
# text_output2 = gr.Label(label="Resultat de prédiction",num_top_classes=3)
|
| 67 |
+
with gr.TabItem("Public- Diabétique, prédiabétique ou sain"):
|
| 68 |
+
# POUR Diabetes
|
| 69 |
+
with gr.Row():
|
| 70 |
+
with gr.Group():
|
| 71 |
+
HighBP = gr.Radio(["Oui","Non"],type="index",label="HighBP")
|
| 72 |
+
HighChol = gr.Radio(["Oui","Non"],type="index",label="HighChol")
|
| 73 |
+
CholCheck = gr.Radio(["Oui","Non"],type="index",label="CholCheck")
|
| 74 |
+
|
| 75 |
+
with gr.Group():
|
| 76 |
+
Smoker = gr.Radio(["Oui","Non"],type="index",label="Smoker")
|
| 77 |
+
Stroke = gr.Radio(["Oui","Non"],type="index",label="Stroke")
|
| 78 |
+
HeartDiseaseorAttack = gr.Radio(["Oui","Non"],type="index",label="HeartDiseaseorAttack")
|
| 79 |
+
|
| 80 |
+
with gr.Group():
|
| 81 |
+
PhysActivity = gr.Radio(["Oui","Non"],type="index",label="PhysActivity")
|
| 82 |
+
Fruits = gr.Radio(["Oui","Non"],type="index",label="Fruits")
|
| 83 |
+
Veggies = gr.Radio(["Oui","Non"],type="index",label="Veggies")
|
| 84 |
+
|
| 85 |
+
with gr.Group():
|
| 86 |
+
HvyAlcoholConsump = gr.Radio(["Oui","Non"],type="index",label="HvyAlcoholConsump")
|
| 87 |
+
AnyHealthcare = gr.Radio(["Oui","Non"],type="index",label="AnyHealthcare")
|
| 88 |
+
NoDocbcCost = gr.Radio(["Oui","Non"],type="index",label="NoDocbcCost")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Group():
|
| 93 |
+
DiffWalk = gr.Radio(["Oui","Non"],type="index",label="DiffWalk")
|
| 94 |
+
Sex = gr.Dropdown(["femme","homme"],type="index",label="Sex")
|
| 95 |
+
with gr.Group():
|
| 96 |
+
BMI = gr.Slider(12, 98,value=70,label="BMI",step=1)
|
| 97 |
+
GenHlth = gr.Slider(1, 5,value=2,label="GenHlth",step=1)
|
| 98 |
+
MentHlth = gr.Slider(0, 30,value=20,label="MentHlth",step=1)
|
| 99 |
+
|
| 100 |
+
with gr.Group():
|
| 101 |
+
PhysHlth = gr.Slider(0, 30,value=14,label="PhysHlth",step=1)
|
| 102 |
+
Age = gr.Slider(1, 13,value=7,label="Age",step=1)
|
| 103 |
+
|
| 104 |
+
with gr.Group():
|
| 105 |
+
Education = gr.Slider(1, 6,value=4,label="Education",step=1)
|
| 106 |
+
Income = gr.Slider(1, 8,value=6,label="Income",step=1)
|
| 107 |
+
|
| 108 |
+
# text_output = gr.Label(num_top_classes=3)
|
| 109 |
+
|
| 110 |
+
Public_diabete_button = gr.Button("Soumettre")
|
| 111 |
+
input_data = [HighBP,HighChol, CholCheck, BMI, Smoker,Stroke,HeartDiseaseorAttack,
|
| 112 |
+
PhysActivity, Fruits, Veggies,HvyAlcoholConsump,AnyHealthcare, NoDocbcCost, GenHlth,
|
| 113 |
+
MentHlth, PhysHlth, DiffWalk,
|
| 114 |
+
Sex, Age, Education,Income]
|
| 115 |
+
output_html2 = gr.outputs.HTML(label="")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
vgg16_button.click(Prediction_VGG16, inputs = my_input,outputs = [output_html])
|
| 120 |
+
PDF_diabete_button.click(get_data_inputPDF, inputs=input_file_PDF,outputs=[df_ouput,output_html1])
|
| 121 |
+
Public_diabete_button.click(user_input, inputs=input_data,outputs=[output_html2])
|
| 122 |
+
|
| 123 |
+
gr.Markdown(
|
| 124 |
+
"""
|
| 125 |
+
|
| 126 |
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
|
| 129 |
+
<html lang="en">
|
| 130 |
+
<head>
|
| 131 |
+
<!-- Required meta tags -->
|
| 132 |
+
<meta charset="utf-8">
|
| 133 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
| 134 |
+
<!-- Bootstrap CSS -->
|
| 135 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
</head>
|
| 140 |
+
<body>
|
| 141 |
+
<p>
|
| 142 |
+
<center>
|
| 143 |
+
<img src="https://huggingface.co/spaces/cnasa/Tumor_and_Diabetes/resolve/main/docaposte.png" alt="docaposte image" width="322" />
|
| 144 |
+
</center>
|
| 145 |
+
</p>
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
<!-- Optional JavaScript -->
|
| 149 |
+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
| 150 |
+
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
|
| 151 |
+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
| 152 |
+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
|
| 153 |
+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
|
| 154 |
+
</body>
|
| 155 |
+
|
| 156 |
|
| 157 |
+
|
| 158 |
+
""")
|
| 159 |
|
|
|
|
| 160 |
|
|
|
|
| 161 |
|
| 162 |
demo.launch()
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
+
#---------------------------------------------------------------------------------------
|
|
|