import gradio as gr import numpy as np import tensorflow as tf # Load the TFLite model interpreter = tf.lite.Interpreter(model_path='efficent_net50.tflite') interpreter.allocate_tensors() input_details = interpreter.get_input_details() output_details = interpreter.get_output_details() def predict(image): # Preprocess the input image to match model input shape image = np.array(image, dtype=np.float32) # Convert to float32 image = np.resize(image, (1, 224, 224, 3)) # Resize to [1, 224, 224, 3] interpreter.set_tensor(input_details[0]['index'], image) interpreter.invoke() output_data = interpreter.get_tensor(output_details[0]['index']) return output_data.tolist() # Return the prediction as a list iface = gr.Interface(fn=predict, inputs="image", outputs="label", title="TFLite Model Inference") iface.launch()