Spaces:
Build error
Build error
adding Inference time feature
Browse files
app.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
|
| 5 |
def predict(input_img):
|
| 6 |
|
|
|
|
| 7 |
# Load the saved Keras model
|
| 8 |
model = tf.keras.models.load_model("VGG19.h5")
|
| 9 |
# Preprocess the image
|
|
@@ -29,14 +31,16 @@ def predict(input_img):
|
|
| 29 |
f'{item[1]} % {class_names[1]}\n'
|
| 30 |
f'{item[2]} % {class_names[2]}\n')
|
| 31 |
plt.imshow(img_0/255)
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
output = gr.Plot()
|
| 36 |
gradio_app = gr.Interface(
|
| 37 |
predict,
|
| 38 |
inputs=gr.Image(label="table type", sources=['upload', 'webcam'], type="pil"),
|
| 39 |
-
outputs=[gr.
|
| 40 |
title="Table-type Classification"
|
| 41 |
)
|
| 42 |
|
|
|
|
| 1 |
+
import time
|
| 2 |
import gradio as gr
|
| 3 |
import tensorflow as tf
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
|
| 6 |
def predict(input_img):
|
| 7 |
|
| 8 |
+
start = time.time()
|
| 9 |
# Load the saved Keras model
|
| 10 |
model = tf.keras.models.load_model("VGG19.h5")
|
| 11 |
# Preprocess the image
|
|
|
|
| 31 |
f'{item[1]} % {class_names[1]}\n'
|
| 32 |
f'{item[2]} % {class_names[2]}\n')
|
| 33 |
plt.imshow(img_0/255)
|
| 34 |
+
end = time.time()
|
| 35 |
+
inf_time = end - start
|
| 36 |
+
return plt, inf_time
|
| 37 |
|
| 38 |
|
| 39 |
output = gr.Plot()
|
| 40 |
gradio_app = gr.Interface(
|
| 41 |
predict,
|
| 42 |
inputs=gr.Image(label="table type", sources=['upload', 'webcam'], type="pil"),
|
| 43 |
+
outputs=[output, gr.Textbox(label="Inference time")],
|
| 44 |
title="Table-type Classification"
|
| 45 |
)
|
| 46 |
|