from keras.models import model_from_json import cv2 import numpy as np class_names = ['Selfie','Non-Selfie'] f = open("model_cnn1.json",'r+') json_string = f.read() f.close() model = model_from_json(json_string) model.load_weights('model_cnn1.h5') model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) def predict_image(img): prediction = model.predict(img.reshape(-1,100,100,3))[0] return {class_names[i]: float(prediction[i]) for i in range(2)} import gradio as gr image = gr.inputs.Image(shape=(100,100),label='Image To Classify') label = gr.outputs.Label(label='Model thinks your image is') gr.Interface(fn=predict_image, inputs=image, outputs=label,allow_flagging='never',title="Selfie Detection Web-App",description="Upload an image to check if it is a Selfie or not?").launch(debug='True')