Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import numpy as np
|
| 7 |
+
from keras.models import load_model
|
| 8 |
+
from tensorflow.keras.utils import load_img
|
| 9 |
+
|
| 10 |
+
# Charger le modèle
|
| 11 |
+
|
| 12 |
+
model = load_model('best_model.h5')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def format_decimal(value):
|
| 16 |
+
decimal_value = format(value, ".2f")
|
| 17 |
+
return decimal_value
|
| 18 |
+
|
| 19 |
+
def detect(img):
|
| 20 |
+
img = np.expand_dims(img, axis=0)
|
| 21 |
+
img = img/255
|
| 22 |
+
# Faire une prédiction
|
| 23 |
+
prediction = model.predict(img)[0]
|
| 24 |
+
|
| 25 |
+
# Initialisation du texte
|
| 26 |
+
texte = ""
|
| 27 |
+
|
| 28 |
+
# Classes prédictives avec leurs index respectifs
|
| 29 |
+
class_names = ['AMAZONE', 'BIOGUERRA', 'REVENANT', 'ZANGBETO']
|
| 30 |
+
|
| 31 |
+
# Détermination du texte pour chaque classe
|
| 32 |
+
for idx, class_name in enumerate(class_names):
|
| 33 |
+
if prediction[idx] >= 0.5:
|
| 34 |
+
texte += f'{class_name} détecté\n'
|
| 35 |
+
|
| 36 |
+
# Si aucune classe n'est détectée
|
| 37 |
+
if texte == "":
|
| 38 |
+
texte = "Classe indéterminée"
|
| 39 |
+
|
| 40 |
+
return texte
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# result = detect(img)
|
| 45 |
+
# print(result)
|
| 46 |
+
# os.system("tar -zxvf examples.tar.gz")
|
| 47 |
+
# examples = ['examples/n1.jpeg', 'examples/n2.jpeg', 'examples/n3.jpeg', 'examples/n4.jpeg', 'examples/n5.jpeg',
|
| 48 |
+
# 'examples/n6.jpeg', 'examples/n7.jpeg', 'examples/n8.jpeg', 'examples/p6.jpeg', 'examples/p7.jpeg',]
|
| 49 |
+
|
| 50 |
+
input = gr.inputs.Image(shape=(100,100))
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
title = "Orisha"
|
| 55 |
+
|
| 56 |
+
iface = gr.Interface(fn=detect, inputs=input, outputs=[gr.Textbox(label="Classe", lines=10)],
|
| 57 |
+
#examples = examples,
|
| 58 |
+
#examples_per_page=20,
|
| 59 |
+
title=title)
|
| 60 |
+
iface.launch(inline=False)
|