kevanme commited on
Commit
02789b3
·
verified ·
1 Parent(s): adc62a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -4,7 +4,7 @@ from tensorflow.keras.models import load_model
4
  from PIL import Image
5
  import tensorflow as tf
6
 
7
- # 🧠 Cargar modelo (asegúrate de que el archivo esté en la raíz del repositorio)
8
  def euclidean_distance(vects):
9
  x, y = vects
10
  sum_square = tf.reduce_sum(tf.square(x - y), axis=1, keepdims=True)
@@ -12,14 +12,14 @@ def euclidean_distance(vects):
12
 
13
  model = load_model("mnist_siamese_model.keras", custom_objects={'euclidean_distance': euclidean_distance})
14
 
15
- # 📌 Preprocesar imágenes
16
  def preprocess(img):
17
  img = img.convert("L").resize((28, 28))
18
  img = np.array(img).astype("float32") / 255.0
19
  img = np.expand_dims(img, axis=-1) # (28, 28, 1)
20
  return img
21
 
22
- # 🔍 Función de predicción
23
  def predict(img1, img2):
24
  img1 = preprocess(img1)
25
  img2 = preprocess(img2)
@@ -29,9 +29,9 @@ def predict(img1, img2):
29
  distance = model.predict([img1, img2])[0][0]
30
  threshold = 0.5
31
  same = distance < threshold
32
- return f"¿Mismo dígito? {'Sí' if same else 'No'} (distancia: {distance:.4f})"
33
 
34
- # 🎛️ Interfaz Gradio
35
  interface = gr.Interface(
36
  fn=predict,
37
  inputs=[
 
4
  from PIL import Image
5
  import tensorflow as tf
6
 
7
+ #Cargar modelo
8
  def euclidean_distance(vects):
9
  x, y = vects
10
  sum_square = tf.reduce_sum(tf.square(x - y), axis=1, keepdims=True)
 
12
 
13
  model = load_model("mnist_siamese_model.keras", custom_objects={'euclidean_distance': euclidean_distance})
14
 
15
+ #Preprocesar imágenes
16
  def preprocess(img):
17
  img = img.convert("L").resize((28, 28))
18
  img = np.array(img).astype("float32") / 255.0
19
  img = np.expand_dims(img, axis=-1) # (28, 28, 1)
20
  return img
21
 
22
+ #Función de predicción
23
  def predict(img1, img2):
24
  img1 = preprocess(img1)
25
  img2 = preprocess(img2)
 
29
  distance = model.predict([img1, img2])[0][0]
30
  threshold = 0.5
31
  same = distance < threshold
32
+ return f"¿Es el mismo dígito? {'Sí' if same else 'No'} (distancia: {distance:.4f})"
33
 
34
+ #Interfaz Gradio
35
  interface = gr.Interface(
36
  fn=predict,
37
  inputs=[