Spaces:
Runtime error
Runtime error
elsamueldev
commited on
Commit
•
792c370
1
Parent(s):
2ad5e69
OKAYY LESGO
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import login, from_pretrained_keras
|
3 |
+
import os
|
4 |
+
import numpy as np
|
5 |
+
import cv2
|
6 |
+
|
7 |
+
login(os.environ["HF_TOKEN"])
|
8 |
+
|
9 |
+
model = from_pretrained_keras("elsamueldev/cats-dogs")
|
10 |
+
|
11 |
+
def predict(img: np.array):
|
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 |
+
pred = model.predict(img)[0][0]
|
20 |
+
|
21 |
+
dog = pred
|
22 |
+
cat = 1 - dog
|
23 |
+
|
24 |
+
return {"dog": dog, "cat": cat}
|
25 |
+
|
26 |
+
gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs="image",
|
29 |
+
outputs="label"
|
30 |
+
).launch()
|