File size: 1,062 Bytes
956bf58
72a1491
63fd6b3
956bf58
63fd6b3
956bf58
 
63fd6b3
956bf58
63fd6b3
 
 
956bf58
63fd6b3
 
956bf58
63fd6b3
 
 
956bf58
63fd6b3
 
f779052
 
7c92a30
 
 
f779052
956bf58
63fd6b3
065c8a4
 
f779052
065c8a4
956bf58
 
63fd6b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import os
from joblib import load
from skimage.transform import resize
from skimage.color import rgb2gray
import numpy as np

classifier = load('knn_classifier.joblib')

def predict_image(image):
  if len(image.shape) == 3:
    image = rgb2gray(image)

  image = resize(image, (8,8),anti_aliasing=True, mode='reflect') #Redimensionamiento
  image = (image * 255).astype(np.uint8)

  #image = np.array(image, dtype = np.float64)
  image = np.invert(image)
  image = image.reshape(1,-1)

  prediction = classifier.predict(image)
  return prediction[0]
    
imagenes_muestra =[
    [os.path.join(os.path.abspath(''), "0.png")],
    [os.path.join(os.path.abspath(''), "5.png")],
    [os.path.join(os.path.abspath(''), "7.png")],
]
iface = gr.Interface(
    fn = predict_image,
    inputs = gr.Image(label = "Sube una imagen de un numero o Selecciona una de los ejemplos"),#"image",
    outputs = gr.Textbox(label = "El resultado es:"),#"text",
    examples = imagenes_muestra
    label = "esta es una prueba de titulo"
)

iface.launch(debug=True)