Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
-
from PIL import Image as PILImage
|
| 5 |
-
import requests
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
# Carregar o modelo .tflite
|
| 9 |
interpreter = tf.lite.Interpreter(model_path="model_unquant.tflite")
|
| 10 |
interpreter.allocate_tensors()
|
| 11 |
|
|
|
|
| 12 |
input_details = interpreter.get_input_details()
|
| 13 |
output_details = interpreter.get_output_details()
|
| 14 |
|
|
|
|
| 15 |
classes = ['Bastonete', 'Basófilo']
|
| 16 |
|
| 17 |
def recognize_image(image):
|
| 18 |
-
# Verificar se a entrada é uma URL
|
| 19 |
-
if isinstance(image, str) and image.startswith("http"):
|
| 20 |
-
response = requests.get(image)
|
| 21 |
-
image = PILImage.open(BytesIO(response.content))
|
| 22 |
-
|
| 23 |
# Redimensionar a imagem para 224x224 (o tamanho esperado pelo modelo)
|
| 24 |
image = PILImage.fromarray(image).resize((224, 224))
|
| 25 |
|
|
@@ -44,10 +39,12 @@ def recognize_image(image):
|
|
| 44 |
|
| 45 |
return f"Classe: {predicted_class_name} (Confiança: {predicted_confidence:.2f}%)"
|
| 46 |
|
|
|
|
| 47 |
interface = gr.Interface(
|
| 48 |
-
fn=recognize_image,
|
| 49 |
-
inputs=
|
| 50 |
-
outputs="text"
|
| 51 |
)
|
| 52 |
|
|
|
|
| 53 |
interface.launch(share=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
+
from PIL import Image as PILImage # Para evitar conflito com Gradio
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Carregar o modelo .tflite
|
| 7 |
interpreter = tf.lite.Interpreter(model_path="model_unquant.tflite")
|
| 8 |
interpreter.allocate_tensors()
|
| 9 |
|
| 10 |
+
# Obter detalhes do modelo
|
| 11 |
input_details = interpreter.get_input_details()
|
| 12 |
output_details = interpreter.get_output_details()
|
| 13 |
|
| 14 |
+
# Classes de saída do modelo
|
| 15 |
classes = ['Bastonete', 'Basófilo']
|
| 16 |
|
| 17 |
def recognize_image(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Redimensionar a imagem para 224x224 (o tamanho esperado pelo modelo)
|
| 19 |
image = PILImage.fromarray(image).resize((224, 224))
|
| 20 |
|
|
|
|
| 39 |
|
| 40 |
return f"Classe: {predicted_class_name} (Confiança: {predicted_confidence:.2f}%)"
|
| 41 |
|
| 42 |
+
# Configurando a interface Gradio
|
| 43 |
interface = gr.Interface(
|
| 44 |
+
fn=recognize_image,
|
| 45 |
+
inputs=gr.Image(), # Removemos o shape
|
| 46 |
+
outputs="text" # Saída: texto com a classe e confiança
|
| 47 |
)
|
| 48 |
|
| 49 |
+
# Lançar o servidor com compartilhamento público
|
| 50 |
interface.launch(share=True)
|