Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
|
| 5 |
+
# Load the TFLite model
|
| 6 |
+
interpreter = tf.lite.Interpreter(model_path='efficent_net50.tflite')
|
| 7 |
+
interpreter.allocate_tensors()
|
| 8 |
+
|
| 9 |
+
input_details = interpreter.get_input_details()
|
| 10 |
+
output_details = interpreter.get_output_details()
|
| 11 |
+
|
| 12 |
+
def predict(image):
|
| 13 |
+
# Preprocess the input image to match model input shape
|
| 14 |
+
image = np.array(image, dtype=np.float32) # Convert to float32
|
| 15 |
+
image = np.resize(image, (1, 224, 224, 3)) # Resize to [1, 224, 224, 3]
|
| 16 |
+
|
| 17 |
+
interpreter.set_tensor(input_details[0]['index'], image)
|
| 18 |
+
interpreter.invoke()
|
| 19 |
+
|
| 20 |
+
output_data = interpreter.get_tensor(output_details[0]['index'])
|
| 21 |
+
return output_data.tolist() # Return the prediction as a list
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(fn=predict, inputs="image", outputs="label", title="TFLite Model Inference")
|
| 24 |
+
iface.launch()
|