Spaces:
Runtime error
Runtime error
File size: 856 Bytes
50db2c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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()
|