File size: 1,159 Bytes
8922014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
os.environ['KERAS-BACKEND'] = 'tensorflow'

import keras_core as keras
import numpy as np
from keras.models import load_model
import cv2
import tensorflow as tf
import tensorflow.image




def image_predict(img_):
    model = load_model('models/final_model.h5')

    img = img_ / 255.0
    img = tf.image.central_crop(img, central_fraction = .85).numpy()
    img = cv2.resize(img, dsize = [224, 224])
    img = np.expand_dims(img, axis = 0)

    pred = model.predict(img, verbose = 1)
    pred = np.argmax(pred, axis = 1)

    if pred == 0:
        answer = "The inputted image is an Airplane"
    elif pred == 1:
        answer = "The inputted image is a Car"

    return answer


# image_ = gr.Image(label = 'Input Image to be predicted')
# output = gr.Textbox(label = 'Prediction')

# demo = gr.Interface(fn = image_predict, inputs = [image_], outputs = output)


with gr.Blocks() as demo:
    image_ = gr.Image(label = 'Input Image to be predicted')
    output = gr.Textbox(label = 'Prediction')
    btn = gr.Button('Predict')
    btn.click(fn = image_predict, inputs = [image_], outputs = output)

demo.launch(share = False)