File size: 1,449 Bytes
4e870dc
3115a57
 
 
 
 
 
4e870dc
3115a57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e55c5e
3115a57
 
 
 
 
 
 
4e870dc
 
 
3115a57
 
 
 
 
 
4e870dc
3115a57
 
 
 
8a3a27c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
import gradio as gr
import tensorflow as tf
import matplotlib.pyplot as plt

def predict(input_img):

    start = time.time()
    # Load the saved Keras model
    model = tf.keras.models.load_model("VGG19.h5")
    # Preprocess the image
    # img_0 = tf.keras.utils.load_img(input_image)
    img_0 = tf.keras.utils.img_to_array(input_img)
    img_0 = tf.image.resize(img_0, (256, 256))
    img_1 = tf.expand_dims(img_0, axis = 0)

    class_names = ["bordered", "borderless", "row_bordered"]

    # Make predictions using the model
    predictions = model.predict(img_1)
    predicted_label = tf.argmax(predictions, 1).numpy().item()

    for item in predictions :
      item = tf.round((item*100))
    
    fig = plt.figure(1, figsize=(8, 14))
    plt.axis('off')
    plt.rcParams.update({'font.size': 24})
    plt.title(f'prediction : {class_names[predicted_label]}\n\n'
              f'{item[0]} % {class_names[0]}\n'
              f'{item[1]} % {class_names[1]}\n'
              f'{item[2]} % {class_names[2]}\n')
    plt.imshow(img_0/255)
    end = time.time()
    inf_time = end - start
    return plt, inf_time

    
output = gr.Plot()
gradio_app = gr.Interface(
    predict,
    inputs=gr.Image(label="table type", sources=['upload', 'webcam'], type="pil"),
    outputs=[output, gr.Textbox(label="Inference time")],
    title="Table-type Classification"
)

if __name__ == "__main__":
    gradio_app.launch(share=True, debug=True)