ML_DEMO / app.py
cnasa's picture
Update app.py
ebc6b24
Raw History Blame Contribute Delete
6.83 kB
import pickle
import pandas as pd
import sklearn
import numpy as np
import gradio as gr
import imblearn
from app_function import *
import tensorflow as tf
from tensorflow.keras.applications import imagenet_utils
from tensorflow.keras.utils import img_to_array
from tensorflow.keras.models import load_model
import pdfplumber
import re
from collections import namedtuple
from compress_pickle import dump, load
demo = gr.Blocks(theme="peach")
with demo:
gr.Markdown(
"""
<p>
<center>
<img src="https://huggingface.co/spaces/cnasa/ML_DEMO/resolve/main/softeam.png" alt="Healthcare thechnology doctor image" width="200"/>
</center>
</p>
# Machine learning DEMO 🐠
---
""")
with gr.Tabs():
with gr.TabItem("Détéction d'une tumeur"):
my_input = gr.inputs.Image(shape=(224,224))
vgg16_button = gr.Button("Soumettre")
output_html = gr.outputs.HTML(label="")
# my_output = gr.Label(label="Resultat de la prédiction",num_top_classes=2)
with gr.TabItem("(PDF) Diabétique, prédiabétique ou sain"):
# POUR DIABETES FICHIER PDF
with gr.Row():
input_file_PDF = gr.File(label='PDF')
PDF_diabete_button = gr.Button("Soumettre")
df_ouput = gr.Dataframe(label="Caractéristique du patient",
headers=["HighBP","HighChol", "CholCheck", "BMI", "Smoker","Stroke","HeartDiseaseorAttack","PhysActivity","Fruits","Veggies","HvyAlcoholConsump","AnyHealthcare", "NoDocbcCost", "GenHlth","MentHlth", "PhysHlth", "DiffWalk","Sex", "Age", "Education","Income"],
row_count=1,col_count=(21),max_rows=2,overflow_row_behaviour='paginate')
output_html1 = gr.outputs.HTML(label="")
# text_output2 = gr.Label(label="Resultat de prédiction",num_top_classes=3)
with gr.TabItem("Public- Diabétique, prédiabétique ou sain"):
# POUR Diabetes
with gr.Row():
with gr.Group():
HighBP = gr.Radio(["Oui","Non"],type="index",label="HighBP")
HighChol = gr.Radio(["Oui","Non"],type="index",label="HighChol")
CholCheck = gr.Radio(["Oui","Non"],type="index",label="CholCheck")
with gr.Group():
Smoker = gr.Radio(["Oui","Non"],type="index",label="Smoker")
Stroke = gr.Radio(["Oui","Non"],type="index",label="Stroke")
HeartDiseaseorAttack = gr.Radio(["Oui","Non"],type="index",label="HeartDiseaseorAttack")
with gr.Group():
PhysActivity = gr.Radio(["Oui","Non"],type="index",label="PhysActivity")
Fruits = gr.Radio(["Oui","Non"],type="index",label="Fruits")
Veggies = gr.Radio(["Oui","Non"],type="index",label="Veggies")
with gr.Group():
HvyAlcoholConsump = gr.Radio(["Oui","Non"],type="index",label="HvyAlcoholConsump")
AnyHealthcare = gr.Radio(["Oui","Non"],type="index",label="AnyHealthcare")
NoDocbcCost = gr.Radio(["Oui","Non"],type="index",label="NoDocbcCost")
with gr.Row():
with gr.Group():
DiffWalk = gr.Radio(["Oui","Non"],type="index",label="DiffWalk")
Sex = gr.Dropdown(["femme","homme"],type="index",label="Sex")
with gr.Group():
BMI = gr.Slider(12, 98,value=70,label="BMI",step=1)
GenHlth = gr.Slider(1, 5,value=2,label="GenHlth",step=1)
MentHlth = gr.Slider(0, 30,value=20,label="MentHlth",step=1)
with gr.Group():
PhysHlth = gr.Slider(0, 30,value=14,label="PhysHlth",step=1)
Age = gr.Slider(1, 13,value=7,label="Age",step=1)
with gr.Group():
Education = gr.Slider(1, 6,value=4,label="Education",step=1)
Income = gr.Slider(1, 8,value=6,label="Income",step=1)
# text_output = gr.Label(num_top_classes=3)
Public_diabete_button = gr.Button("Soumettre")
input_data = [HighBP,HighChol, CholCheck, BMI, Smoker,Stroke,HeartDiseaseorAttack,
PhysActivity, Fruits, Veggies,HvyAlcoholConsump,AnyHealthcare, NoDocbcCost, GenHlth,
MentHlth, PhysHlth, DiffWalk,
Sex, Age, Education,Income]
output_html2 = gr.outputs.HTML(label="")
vgg16_button.click(Prediction_VGG16, inputs =my_input,outputs = [output_html])
PDF_diabete_button.click(get_data_inputPDF, inputs=input_file_PDF,outputs=[df_ouput,output_html1])
Public_diabete_button.click(user_input, inputs=input_data,outputs=[output_html2])
gr.Markdown(
"""
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<p>
<center>
<img src="https://huggingface.co/spaces/cnasa/ML_DEMO/resolve/main/docaposte.png" alt="docaposte image" width="322" />
</center>
</p>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<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>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
""")
demo.launch()
#---------------------------------------------------------------------------------------