Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as input
|
4 |
|
5 |
+
num_classes = 200
|
6 |
+
IMG_HEIGHT = 256
|
7 |
+
IMG_WIDTH = 256
|
8 |
|
9 |
+
def normalize_image(img):
|
10 |
+
img = tf.cast(img, tf.float32)/255.
|
11 |
+
img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH), method='bilinear')
|
12 |
+
return img
|
13 |
+
|
14 |
+
|
15 |
+
def predict_fn(img):
|
16 |
+
img = img.convert('RGB')
|
17 |
+
img_data = normalize_image(img)
|
18 |
+
x = np.array(img_data)
|
19 |
+
x = np.expand_dims(x, axis=0)
|
20 |
+
temp = model.predict(x)
|
21 |
+
return temp
|
22 |
+
|
23 |
+
|
24 |
+
model = tf.keras.models.load_model("model.h5")
|
25 |
+
|
26 |
+
interface = gr.Interface(predict_fn, gr.inputs.Image(type='PIL'), outputs='label', examples=path,)
|
27 |
+
interface.launch()
|