File size: 1,328 Bytes
086b0fb b1325b9 086b0fb b1325b9 086b0fb b1325b9 086b0fb b1325b9 086b0fb b1325b9 086b0fb b1325b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
import tensorflow as tf
import numpy as np
from keras.models import load_model
from tensorflow.keras.utils import load_img, img_to_array
# Charger le modèle
model = load_model('best_model.h5')
def format_decimal(value):
decimal_value = format(value, ".2f")
return decimal_value
def detect(img):
# Prétraiter l'image
img = img.resize((256, 256)) # Redimensionner l'image
img = img_to_array(img)
img = np.expand_dims(img, axis=0)
img = img / 255.0 # Normaliser les valeurs de l'image
# Faire une prédiction
prediction = model.predict(img)[0]
# Initialisation du texte
texte = ""
# Classes prédictives avec leurs index respectifs
class_names = ['AMAZONE', 'BIOGUERRA', 'REVENANT', 'ZANGBETO']
# Détermination du texte pour chaque classe
for idx, class_name in enumerate(class_names):
if prediction[idx] >= 0.5:
texte += f'{class_name} détecté\n'
# Si aucune classe n'est détectée
if texte == "":
texte = "Classe indéterminée"
return texte
title = "Orisha"
iface = gr.Interface(fn=detect,
inputs=gr.Image(type="pil", shape=(256, 256)),
outputs=gr.Textbox(label="Classe", lines=10),
title=title)
iface.launch(inline=False)
|