Upload inference.py with huggingface_hub
Browse files- inference.py +19 -0
inference.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Cargar el modelo
|
6 |
+
model = joblib.load("decision_tree_model.joblib")
|
7 |
+
|
8 |
+
# Funci贸n para cargar y aplanar una imagen
|
9 |
+
def load_and_flatten_image(image_path):
|
10 |
+
img = Image.open(image_path)
|
11 |
+
img = img.resize((28, 28))
|
12 |
+
img_array = np.array(img)
|
13 |
+
img_flat = img_array.flatten()
|
14 |
+
return img_flat
|
15 |
+
|
16 |
+
def predict(image_path):
|
17 |
+
img_flat = load_and_flatten_image(image_path)
|
18 |
+
prediction = model.predict([img_flat])
|
19 |
+
return prediction[0]
|