Spaces:
Sleeping
Sleeping
| 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] | |
| 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) |