Update app.py
Browse files
app.py
CHANGED
|
@@ -2,10 +2,17 @@ import gradio as gr
|
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
# Carregue o modelo previamente treinado
|
| 7 |
model = tf.keras.models.load_model("model.h5")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Crie uma função para realizar a classificação
|
| 10 |
def classify_image(image):
|
| 11 |
try:
|
|
@@ -19,7 +26,7 @@ def classify_image(image):
|
|
| 19 |
|
| 20 |
# Decodifique a classe prevista
|
| 21 |
class_idx = np.argmax(prediction)
|
| 22 |
-
class_label = categories[class_idx]
|
| 23 |
|
| 24 |
return class_label
|
| 25 |
except Exception as e:
|
|
|
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
# Carregue o modelo previamente treinado
|
| 8 |
model = tf.keras.models.load_model("model.h5")
|
| 9 |
|
| 10 |
+
# Carregue o arquivo JSON com as categorias indexadas
|
| 11 |
+
with open("categories.json", "r") as json_file:
|
| 12 |
+
categories_data = json.load(json_file)
|
| 13 |
+
|
| 14 |
+
categories = [entry["category"] for entry in categories_data]
|
| 15 |
+
|
| 16 |
# Crie uma função para realizar a classificação
|
| 17 |
def classify_image(image):
|
| 18 |
try:
|
|
|
|
| 26 |
|
| 27 |
# Decodifique a classe prevista
|
| 28 |
class_idx = np.argmax(prediction)
|
| 29 |
+
class_label = categories[class_idx]
|
| 30 |
|
| 31 |
return class_label
|
| 32 |
except Exception as e:
|