Spaces:
Runtime error
Runtime error
Commit
·
509d552
1
Parent(s):
b8dfa73
Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,20 @@ login(os.environ["HF_TOKEN"])
|
|
8 |
|
9 |
model = from_pretrained_keras("elsamueldev/cats-dogs")
|
10 |
|
11 |
-
|
|
|
12 |
img = cv2.resize(img, (100, 100)) # resize to 100x100
|
13 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale
|
14 |
img = img.reshape(100, 100, 1) # reshape to 100x100x1
|
15 |
img = img / 255 # normalize
|
16 |
img = np.array([img]) # reshape to 1x100x100x1
|
17 |
|
|
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
-
dog =
|
22 |
cat = 1 - dog
|
23 |
|
24 |
return {"dog": dog, "cat": cat}
|
|
|
8 |
|
9 |
model = from_pretrained_keras("elsamueldev/cats-dogs")
|
10 |
|
11 |
+
|
12 |
+
def preprocess(img: np.array) -> np.array:
|
13 |
img = cv2.resize(img, (100, 100)) # resize to 100x100
|
14 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale
|
15 |
img = img.reshape(100, 100, 1) # reshape to 100x100x1
|
16 |
img = img / 255 # normalize
|
17 |
img = np.array([img]) # reshape to 1x100x100x1
|
18 |
|
19 |
+
return img
|
20 |
|
21 |
+
def predict(img: np.array):
|
22 |
+
img = preprocess(img)
|
23 |
|
24 |
+
dog = model.predict(img)[0][0]
|
25 |
cat = 1 - dog
|
26 |
|
27 |
return {"dog": dog, "cat": cat}
|