Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from skimage.io import imread
|
4 |
from skimage.transform import resize
|
|
|
5 |
import numpy as np
|
6 |
|
7 |
-
|
8 |
-
classifier = KNeighborsClassifier(n_neighbors=5)
|
9 |
-
# Cargar el conjunto de datos o modelo pre-entrenado
|
10 |
-
# Por ejemplo, puedes cargar el mismo conjunto de datos de d铆gitos que usaste en tu c贸digo original o uno similar.
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
user_image = imread(image)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
|
|
24 |
|
25 |
-
# Crea una interfaz de Gradio
|
26 |
iface = gr.Interface(
|
27 |
-
fn=
|
28 |
-
inputs="image",
|
29 |
-
outputs="text"
|
30 |
-
title="Clasificador KNN de D铆gitos",
|
31 |
-
description="Sube una imagen de un d铆gito (8x8 p铆xeles) y predice el n煤mero."
|
32 |
)
|
33 |
|
34 |
-
|
35 |
-
iface.launch(debug = True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from joblib import load
|
|
|
3 |
from skimage.transform import resize
|
4 |
+
from skimage.color import rgb2gray
|
5 |
import numpy as np
|
6 |
|
7 |
+
classifier = load('knn_classifier.joblib')
|
|
|
|
|
|
|
8 |
|
9 |
+
def predict_image(image):
|
10 |
+
if len(image.shape) == 3:
|
11 |
+
image = rgb2gray(image)
|
|
|
12 |
|
13 |
+
image = resize(image, (8,8),anti_aliasing=True, mode='reflect') #Redimensionamiento
|
14 |
+
image = (image * 255).astype(np.uint8)
|
15 |
|
16 |
+
#image = np.array(image, dtype = np.float64)
|
17 |
+
image = np.invert(image)
|
18 |
+
image = image.reshape(1,-1)
|
19 |
|
20 |
+
prediction = classifier.predict(image)
|
21 |
+
return prediction[0]
|
22 |
|
|
|
23 |
iface = gr.Interface(
|
24 |
+
fn = predict_image,
|
25 |
+
inputs = "image",
|
26 |
+
outputs = "text"
|
|
|
|
|
27 |
)
|
28 |
|
29 |
+
iface.launch(debug=True)
|
|