import gradio as gr import tensorflow as tf import numpy as np from PIL import Image model = tf.keras.models.load_model('my_model.h5') labels = ["No rotated","Rotared to left","Upside down","Rotared to right"] sample_images = [["0.jpeg"],["90.jpeg"],["180.jpeg"],["270.jpeg"]] def classify_image(inp): inp = tf.keras.preprocessing.image.load_img(inp.name, target_size=(90,90)) img_array = tf.keras.preprocessing.image.img_to_array(inp) a_file = open("gradio.txt", "w") for row in img_array: np.savetxt(a_file, row) a_file.close() img_array = tf.expand_dims(inp, 0) # Create a batch prediction = model.predict(img_array) score = tf.nn.softmax(prediction[0]) return {labels[np.argmax(score)]:1 * np.max(score) for i in range(4)} image = gr.inputs.Image(type="file", invert_colors=False) label = gr.outputs.Label(num_top_classes=1) gr.Interface(fn=classify_image, inputs=image, examples = sample_images, outputs=label, allow_flagging=None, title="Scan rotation app", theme="dark").launch()