import gradio as gr import tensorflow as tf from huggingface_hub import from_pretrained_keras # Load your trained models model1 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101") model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101") with open('classes.txt', 'r') as f: classes = [line.strip() for line in f] # Add information about the models model1_info = """ ### Model 1 Information This model is based on the EfficientNetB0 architecture and was trained on the Food101 dataset. """ model2_info = """ ### Model 2 Information This model is based on the EfficientNetB0 architecture and was trained on augmented data, providing improved generalization. """ def preprocess(image): image = tf.image.resize(image, [224, 224]) image = tf.expand_dims(image, axis=0) return image def predict(model_selection, image): # Choose the model based on the dropdown selection model = model1 if model_selection == "EfficentNetB0 Fine Tune" else model2 image = preprocess(image) prediction = model.predict(image) print("model prediction", prediction) predicted_class = classes[int(tf.argmax(prediction, axis=1))] confidence = tf.reduce_max(prediction).numpy() return predicted_class, confidence iface = gr.Interface( fn=predict, inputs=[gr.Dropdown(["EfficentNetB0 Fine Tune", "EfficentNetB0 Fine Tune Augmented"]), gr.Image()], outputs=[gr.Textbox(label="Predicted Class"), gr.Textbox(label="Confidence")], title="Transfer Learning Mini Project", description=f"{model1_info}\n\n{model2_info}", ) iface.launch()