File size: 1,559 Bytes
956bf58
63fd6b3
956bf58
63fd6b3
956bf58
 
63fd6b3
956bf58
63fd6b3
 
 
956bf58
63fd6b3
 
956bf58
63fd6b3
 
 
956bf58
63fd6b3
 
f779052
e9f69f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f779052
 
 
 
 
 
956bf58
63fd6b3
f779052
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
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]
    
with gr.Blocks() as demo:
    txt = gr.Textbox(label = "Input", lines =2)
    txt_2 = gr.Textbox(label = "Input 2")
    txt_3 = gr.Textbox(value = "", label = "Output")
    btn = gr.Button(value = "submit")
    btn.click(combine, inputs = [txt, txt_2]), outputs = [txt_3]

    with gr.Row():
        im = gr.Image()
        im_2 = gr.Image()

    btn = gr.Button(value = "Mirror image")
    btn.click(mirror, inputs = [im], outputs = [im_2])

    gr.Markdown("## Image Examples")
    gr.Examples(
        examples=[os.path.join(os.path.dirname(__file__), "0.png")],
        inputs=im,
        outputs=im_2,
        fn=mirror,
        cache_examples=True,
    )


imagenes_muestra =[
    "knnExample/0.png"
    "knnExample/5.png"
    "knnExample/7.png"
    
]
iface = gr.Interface(
    fn = predict_image,
    inputs = gr.inputs.Image(type = "file", label = "Sube tu Imagen o Selecciona una de Ejemplo"),#"image",
    outputs = "text",
    examples = imagenes_muestra
)

iface.launch(debug=True)