imanolcb commited on
Commit
d2e0005
verified
1 Parent(s): e39fbba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -3,13 +3,13 @@ import tensorflow as tf
3
  import numpy as np
4
  from tensorflow.keras.preprocessing import image
5
 
6
- # Cargar el modelo (se asume que el archivo .keras est谩 en el repositorio del Space)
7
  def load_model():
8
- return tf.keras.models.load_model("modelo_frutas_transfer.h5")
9
 
10
  model = load_model()
11
 
12
- # Lista de clases (aj煤stala si es necesario)
13
  class_names = ['Manzana', 'Banana', 'Naranja', 'Pera', 'Uva']
14
 
15
  # Funci贸n de predicci贸n
@@ -18,10 +18,10 @@ def predict_image(image_input):
18
  img_array = image.img_to_array(img) / 255.0
19
  img_array = np.expand_dims(img_array, axis=0)
20
  pred = model.predict(img_array)
21
- predicted_class = np.argmax(pred, axis=1)
22
- return class_names[predicted_class[0]]
23
 
24
- # Interfaz con Gradio
25
  iface = gr.Interface(
26
  fn=predict_image,
27
  inputs=gr.Image(type="file", label="Cargar imagen de fruta"),
 
3
  import numpy as np
4
  from tensorflow.keras.preprocessing import image
5
 
6
+ # Cargar el modelo (.keras)
7
  def load_model():
8
+ return tf.keras.models.load_model("modelo_frutas_transfer.keras")
9
 
10
  model = load_model()
11
 
12
+ # Clases del modelo (ajusta si es necesario)
13
  class_names = ['Manzana', 'Banana', 'Naranja', 'Pera', 'Uva']
14
 
15
  # Funci贸n de predicci贸n
 
18
  img_array = image.img_to_array(img) / 255.0
19
  img_array = np.expand_dims(img_array, axis=0)
20
  pred = model.predict(img_array)
21
+ predicted_class = np.argmax(pred, axis=1)[0]
22
+ return class_names[predicted_class]
23
 
24
+ # Interfaz Gradio
25
  iface = gr.Interface(
26
  fn=predict_image,
27
  inputs=gr.Image(type="file", label="Cargar imagen de fruta"),