import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Load your model here model = tf.keras.models.load_model('food_or_not.keras') def prob(x): probs = { "Food": 0.5, "Not Food": 0.5 } if(x<0.5): probs["Food"] = (1-(x*2)) probs["Not Food"] = (x*2) else: probs["Food"] = 1-(1-((1-x)*2)) probs["Not Food"] = (1-((1-x)*2)) return probs def get_pred(img): img = img.resize((224, 224)) img = np.array(img) img = np.expand_dims(img, axis=0) val = model.predict(img) val = val[0][0] # print(val) # if val < 0.5: # return "Food" # else: # return "Not Food" return prob(val) # iface = gr.Interface( # fn=get_pred, # inputs=gr.inputs.Image(type="pil", label="Upload an Image"), # outputs=gr.outputs.Textbox(label="Prediction"), # title="Food or Not Food Classifier", # description="Upload an image to check if it contains food or not.", # examples=["example1.jpg", "example2.png"] # Provide paths to example images # ) iface = gr.Interface( fn=get_pred, inputs=gr.inputs.Image(type="pil", label="Upload an Image"), outputs=gr.outputs.Label(num_top_classes=2, label="Prediction"), title="Food or Not Food Classifier", description="Upload an image to check if it contains food or not.", examples=["example1.jpg", "example2.png"] # Provide paths to example images ) iface.launch()