Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,14 +43,25 @@ def classify_image(inp):
|
|
| 43 |
# Faça uma previsão usando o modelo treinado
|
| 44 |
prediction = loaded_model.predict(np.expand_dims(img, axis=0)).flatten()
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Crie uma interface Gradio
|
| 50 |
iface = gr.Interface(
|
| 51 |
fn=classify_image,
|
| 52 |
inputs=gr.inputs.Image(shape=(192, 256)),
|
| 53 |
-
outputs=gr.outputs.Label(),
|
| 54 |
capture_session=True,
|
| 55 |
title="Detecção de Catarata",
|
| 56 |
description="Esta interface permite a detecção de catarata em imagens de olhos.",
|
|
|
|
| 43 |
# Faça uma previsão usando o modelo treinado
|
| 44 |
prediction = loaded_model.predict(np.expand_dims(img, axis=0)).flatten()
|
| 45 |
|
| 46 |
+
# Obtém a classe prevista
|
| 47 |
+
predicted_class = class_names[np.argmax(prediction)]
|
| 48 |
+
|
| 49 |
+
# Crie uma imagem de saída com a classe prevista
|
| 50 |
+
output_image = Image.new("RGB", (256, 192))
|
| 51 |
+
output_image.paste((255, 255, 255), (0, 0, 256, 192))
|
| 52 |
+
output_image_draw = ImageDraw.Draw(output_image)
|
| 53 |
+
output_image_draw.text((10, 10), f"Classe Prevista: {predicted_class}", fill=(0, 0, 0))
|
| 54 |
+
|
| 55 |
+
# Converte a imagem de saída de volta para numpy array
|
| 56 |
+
output_image = np.array(output_image)
|
| 57 |
+
|
| 58 |
+
return predicted_class, output_image
|
| 59 |
|
| 60 |
# Crie uma interface Gradio
|
| 61 |
iface = gr.Interface(
|
| 62 |
fn=classify_image,
|
| 63 |
inputs=gr.inputs.Image(shape=(192, 256)),
|
| 64 |
+
outputs=[gr.outputs.Label(), gr.outputs.Image(type="numpy")],
|
| 65 |
capture_session=True,
|
| 66 |
title="Detecção de Catarata",
|
| 67 |
description="Esta interface permite a detecção de catarata em imagens de olhos.",
|