maquet/Classification
0
1import gradio as gr2import cv23import numpy as np4from tensorflow import keras5 6img_size = 2247#import model8model = keras.models.load_model('pruned_model54_83.h5')9model.compile(optimizer='adam',10 loss="categorical_crossentropy",11 metrics=['accuracy'])12#input: Image location Path13def Predict_Image(image):14 15 #read image16 # image = cv2.imread(image, cv2.IMREAD_COLOR)17 #preprocessing18 img = cv2.resize(image, (img_size, img_size))19 #prediction: output -> array with probabilities of a picture's relation to some class20 21 prediction = model.predict(np.array([img]),verbose=1)22 # if max prob = to 8(class), it's receipt 23 if np.argmax(prediction) == 8:24 is_receipt = "True"25 else:26 is_receipt = "False"27 #output: Bool28 return is_receipt29 30 31title='Receipts Classifier'32 33# interface.launch()34gr.Interface(fn=Predict_Image,inputs='image',outputs=['text'],title=title).launch()35 36 