Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
|
|
|
| 3 |
|
| 4 |
-
model = tf.keras.models.load_model(
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
iface = gr.Interface(fn=predict, inputs="image", outputs="label")
|
| 15 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
+
model = tf.keras.models.load_model('JaviSwift/cifar10_simple')
|
| 6 |
|
| 7 |
+
def predict_image(img):
|
| 8 |
+
"""
|
| 9 |
+
Realiza la predicci贸n sobre la imagen dada usando el modelo Keras.
|
| 10 |
+
"""
|
| 11 |
|
| 12 |
+
img = tf.image.resize(img, (32, 32))
|
| 13 |
+
img = img / 255.0
|
| 14 |
+
img = np.expand_dims(img, axis=0)
|
| 15 |
+
|
| 16 |
+
prediction = model.predict(img)
|
| 17 |
+
|
| 18 |
+
predicted_class = np.argmax(prediction)
|
| 19 |
+
|
| 20 |
+
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
|
| 21 |
+
predicted_label = class_names[predicted_class]
|
| 22 |
+
|
| 23 |
+
return predicted_label
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=predict_image,
|
| 28 |
+
inputs=gr.Image(shape=(32, 32), image_mode="RGB", source="upload", tool="editor"),
|
| 29 |
+
outputs=gr.Label(num_top_classes=3),
|
| 30 |
+
title="Clasificador de Im谩genes con Keras",
|
| 31 |
+
description="Cargue una imagen para clasificarla usando un modelo Keras entrenado en CIFAR-10."
|
| 32 |
+
)
|
| 33 |
|
|
|
|
| 34 |
iface.launch()
|