JojoHaba commited on
Commit
33cc6e8
·
verified ·
1 Parent(s): 9c4b036

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ import gradio as gr
4
+ from PIL import Image
5
+
6
+ # 1. Charger le modèle entraîné (.h5)
7
+ model = tf.keras.models.load_model("CNN_model.h5") # change le nom si besoin
8
+
9
+ # 2. Définir les classes CIFAR-10
10
+ classes = [
11
+ "airplane", "automobile", "bird", "cat", "deer",
12
+ "dog", "frog", "horse", "ship", "truck"
13
+ ]
14
+
15
+ # 3. Fonction de prétraitement + prédiction
16
+ def predict(image):
17
+ image = image.resize((32, 32)) # Redimensionner à 32x32
18
+ image_array = np.array(image) / 255.0 # Normaliser
19
+ image_array = image_array.reshape(1, 32, 32, 3) # Ajouter batch dimension
20
+ predictions = model.predict(image_array)[0]
21
+ result = {classes[i]: float(predictions[i]) for i in range(10)}
22
+ return result
23
+
24
+ # 4. Interface Gradio
25
+ gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.Image(type="pil"),
28
+ outputs=gr.Label(num_top_classes=3),
29
+ title="Classificateur CIFAR-10",
30
+ description="Téléverse une image pour prédire sa classe parmi les 10 catégories CIFAR-10."
31
+ ).launch()
32
+