Upload 3 files
Browse files- app.py +29 -0
- model_unquant.tflite +3 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Carregar o modelo .tflite
|
| 7 |
+
interpreter = tf.lite.Interpreter(model_path="model_unquant.tflite")
|
| 8 |
+
interpreter.allocate_tensors()
|
| 9 |
+
|
| 10 |
+
# Detalhes da entrada e saída do modelo
|
| 11 |
+
input_details = interpreter.get_input_details()
|
| 12 |
+
output_details = interpreter.get_output_details()
|
| 13 |
+
|
| 14 |
+
def predict(image):
|
| 15 |
+
# Redimensiona a imagem para o tamanho necessário pelo modelo
|
| 16 |
+
image = image.resize((224, 224)) # Ajuste para o tamanho que seu modelo exige
|
| 17 |
+
image = np.expand_dims(np.array(image), axis=0).astype(np.float32)
|
| 18 |
+
|
| 19 |
+
# Realiza a inferência
|
| 20 |
+
interpreter.set_tensor(input_details[0]['index'], image)
|
| 21 |
+
interpreter.invoke()
|
| 22 |
+
output = interpreter.get_tensor(output_details[0]['index'])
|
| 23 |
+
|
| 24 |
+
# O resultado pode precisar ser ajustado conforme a saída do modelo
|
| 25 |
+
return output.tolist() # Retorna o resultado da inferência
|
| 26 |
+
|
| 27 |
+
# Configurando a interface Gradio
|
| 28 |
+
interface = gr.Interface(fn=predict, inputs="image", outputs="label")
|
| 29 |
+
interface.launch()
|
model_unquant.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cab17f7a148b26dd9a84ecddaaea8303e04e078d964a180a15749336fe5322f0
|
| 3 |
+
size 2090332
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
pillow
|
| 3 |
+
gradio
|
| 4 |
+
numpy
|
| 5 |
+
|