First commit
Browse files- gradio_app.py +56 -0
- keras_model.h5 +3 -0
- labels.txt +5 -0
gradio_app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model # type: ignore
|
3 |
+
from PIL import Image, ImageOps # Install pillow instead of PIL
|
4 |
+
import numpy as np
|
5 |
+
from tensorflow.keras.layers import DepthwiseConv2D # type: ignore
|
6 |
+
|
7 |
+
# Définir la couche sans le paramètre 'groups'
|
8 |
+
def custom_depthwise_conv2d(*args, **kwargs):
|
9 |
+
if 'groups' in kwargs:
|
10 |
+
del kwargs['groups'] # Retirer 'groups'
|
11 |
+
return DepthwiseConv2D(*args, **kwargs)
|
12 |
+
|
13 |
+
# Charger le modèle
|
14 |
+
model = load_model("models/keras_model.h5", custom_objects={'DepthwiseConv2D': custom_depthwise_conv2d}, compile=False)
|
15 |
+
|
16 |
+
# Charger les étiquettes
|
17 |
+
with open("labels.txt", "r") as file:
|
18 |
+
class_names = file.readlines()
|
19 |
+
|
20 |
+
# Fonction pour prédire la classe d'une image
|
21 |
+
def predict(image):
|
22 |
+
# Redimensionner l'image à 224x224
|
23 |
+
image = ImageOps.fit(image, (224, 224), Image.Resampling.LANCZOS)
|
24 |
+
|
25 |
+
# Convertir l'image en tableau numpy
|
26 |
+
image_array = np.asarray(image)
|
27 |
+
|
28 |
+
# Normaliser l'image
|
29 |
+
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
|
30 |
+
|
31 |
+
# Créer le tableau de données pour le modèle
|
32 |
+
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
33 |
+
data[0] = normalized_image_array
|
34 |
+
|
35 |
+
# Prédire avec le modèle
|
36 |
+
prediction = model.predict(data)
|
37 |
+
index = np.argmax(prediction)
|
38 |
+
class_name = class_names[index].strip() # Supprimer les espaces supplémentaires
|
39 |
+
confidence_score = prediction[0][index]
|
40 |
+
|
41 |
+
return class_name, confidence_score
|
42 |
+
|
43 |
+
# Créer l'interface Gradio
|
44 |
+
iface = gr.Interface(
|
45 |
+
fn=predict,
|
46 |
+
inputs=gr.Image(type="pil", label="Téléchargez une image"),
|
47 |
+
outputs=[
|
48 |
+
gr.Label(label="Classe Prédite"),
|
49 |
+
gr.Number(label="Score de Confiance")
|
50 |
+
],
|
51 |
+
title="Medical Assistant",
|
52 |
+
description="Téléchargez une image dentaire et notre application prédira sa classe."
|
53 |
+
)
|
54 |
+
|
55 |
+
# Lancer l'interface
|
56 |
+
iface.launch(api_show=False)
|
keras_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:89b625e9c3ec4dec9d7411f12885e0bb97eed40eb7b0eb9ee1aa9acae8c18549
|
3 |
+
size 2456608
|
labels.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Dental Caries
|
2 |
+
Calculus
|
3 |
+
Gingivitis
|
4 |
+
Hypodontia
|
5 |
+
Tooth discoloration
|