Spaces:
Build error
Build error
added application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 10 |
+
# img_0 = tf.keras.utils.load_img(input_image)
|
| 11 |
+
img_0 = tf.keras.utils.img_to_array(input_img)
|
| 12 |
+
img_0 = tf.image.resize(img_0, (256, 256))
|
| 13 |
+
img_1 = tf.expand_dims(img_0, axis = 0)
|
| 14 |
+
|
| 15 |
+
class_names = ["bordered", "borderless", "row_bordered"]
|
| 16 |
+
|
| 17 |
+
# Make predictions using the model
|
| 18 |
+
predictions = model.predict(img_1)
|
| 19 |
+
predicted_label = tf.argmax(predictions, 1).numpy().item()
|
| 20 |
+
|
| 21 |
+
for item in predictions :
|
| 22 |
+
item = tf.round((item*100))
|
| 23 |
+
|
| 24 |
+
fig = plt.figure(1, figsize=(8, 10))
|
| 25 |
+
plt.axis('off')
|
| 26 |
+
plt.rcParams.update({'font.size': 24})
|
| 27 |
+
plt.title(f'prediction : {class_names[predicted_label]}\n\n'
|
| 28 |
+
f'{item[0]} % {class_names[0]}\n'
|
| 29 |
+
f'{item[1]} % {class_names[1]}\n'
|
| 30 |
+
f'{item[2]} % {class_names[2]}\n')
|
| 31 |
+
plt.imshow(img_0/255)
|
| 32 |
+
return input_img, plt
|
| 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.Image(label="Processed Image"), output],
|
| 40 |
+
title="Table-type Classification"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
gradio_app.launch(debug=True)
|