Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|