Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +39 -0
- mnist_siamese_model.keras +3 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
mnist_siamese_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
|
5 |
+
# Cargar el modelo guardado en formato .keras
|
6 |
+
siamese_model = tf.keras.models.load_model("mnist_siamese_model.keras")
|
7 |
+
|
8 |
+
# Función de predicción
|
9 |
+
def predict(img1, img2):
|
10 |
+
# Preprocesar las imágenes: convertir a escala de grises, redimensionar, normalizar
|
11 |
+
img1 = img1.convert('L').resize((28, 28))
|
12 |
+
img2 = img2.convert('L').resize((28, 28))
|
13 |
+
|
14 |
+
arr1 = np.array(img1).astype('float32') / 255.0
|
15 |
+
arr2 = np.array(img2).astype('float32') / 255.0
|
16 |
+
|
17 |
+
arr1 = np.expand_dims(arr1, axis=(0, -1)) # (1, 28, 28, 1)
|
18 |
+
arr2 = np.expand_dims(arr2, axis=(0, -1))
|
19 |
+
|
20 |
+
# Realizar la predicción
|
21 |
+
pred = siamese_model.predict([arr1, arr2])[0][0]
|
22 |
+
resultado = "Iguales ✅" if pred > 0.5 else "Diferentes ❌"
|
23 |
+
return f"{resultado} (Confianza: {pred:.2f})"
|
24 |
+
|
25 |
+
# Crear la interfaz Gradio
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs=[
|
29 |
+
gr.Image(label="Imagen 1", shape=(28, 28)),
|
30 |
+
gr.Image(label="Imagen 2", shape=(28, 28))
|
31 |
+
],
|
32 |
+
outputs=gr.Text(label="Resultado"),
|
33 |
+
title="🔗 Verificación Siamese MNIST",
|
34 |
+
description="Sube dos imágenes de dígitos escritos a mano y verifica si son el mismo número.",
|
35 |
+
)
|
36 |
+
|
37 |
+
# Lanzar la app (Hugging Face lo hace automáticamente)
|
38 |
+
iface.launch()
|
39 |
+
|
mnist_siamese_model.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0f0830902e503d0f4321af66cba33cdb198fc8cee44f53adabb0c3deefd21c2b
|
3 |
+
size 5966069
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
gradio
|
3 |
+
numpy
|
4 |
+
pillow
|
5 |
+
|