JaviSwift commited on
Commit
d15cad2
verified
1 Parent(s): 3876fb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
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("hf://JaviSwift/cifar10_simple") # Cambia esto por tu usuario y nombre del modelo
5
 
6
- def predict(image):
7
- image = tf.image.resize(image, (32, 32)) # Ajusta seg煤n tu modelo
8
- image = image / 255.0 # Normaliza si es necesario
9
- image = tf.expand_dims(image, axis=0) # A帽ade dimensi贸n para batch
10
 
11
- predictions = model.predict(image)
12
- return predictions.argmax(axis=1)[0] # Devuelve la clase predicha
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()