Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,30 +4,37 @@ import numpy as np
|
|
4 |
import gradio as gr
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
def greet(name):
|
8 |
return "Hello " + name + "!!"
|
9 |
|
10 |
-
def predict(img):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
return prediction
|
32 |
|
33 |
|
|
|
4 |
import gradio as gr
|
5 |
|
6 |
|
7 |
+
# Load the model
|
8 |
+
model = load_model('keras_model.h5')
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
def greet(name):
|
13 |
return "Hello " + name + "!!"
|
14 |
|
15 |
+
def predict(img):
|
16 |
+
|
17 |
+
# Create the array of the right shape to feed into the keras model
|
18 |
+
# The 'length' or number of images you can put into the array is
|
19 |
+
# determined by the first position in the shape tuple, in this case 1.
|
20 |
+
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
21 |
+
# Replace this with the path to your image
|
22 |
+
image = Image.open('<IMAGE_PATH>')
|
23 |
+
#resize the image to a 224x224 with the same strategy as in TM2:
|
24 |
+
#resizing the image to be at least 224x224 and then cropping from the center
|
25 |
+
size = (224, 224)
|
26 |
+
image = ImageOps.fit(image, size, Image.ANTIALIAS)
|
27 |
+
|
28 |
+
#turn the image into a numpy array
|
29 |
+
image_array = np.asarray(image)
|
30 |
+
# Normalize the image
|
31 |
+
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|
32 |
+
# Load the image into the array
|
33 |
+
data[0] = normalized_image_array
|
34 |
+
|
35 |
+
# run the inference
|
36 |
+
prediction = model.predict(data)
|
37 |
+
print(prediction)
|
38 |
return prediction
|
39 |
|
40 |
|