DHEIVER commited on
Commit
fd93f84
1 Parent(s): 6c07df1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -3,6 +3,7 @@ import efficientnet.tfkeras as efn
3
  from tensorflow.keras.layers import Input, GlobalAveragePooling2D, Dense
4
  import numpy as np
5
  import gradio as gr
 
6
 
7
  # Dimensões da imagem
8
  IMG_HEIGHT = 224
@@ -66,15 +67,32 @@ def predict_image(input_image):
66
  # For example:
67
  # formatted_text = f"Predicted Class: {predicted_class}\nProbability: {probability:.2%}\nObject Detection: {bounding_box_coordinates}"
68
 
69
- # Return the formatted result
70
- formatted_text = f"Predicted Class: {predicted_class}\nProbability: {probability:.2%}"
71
- return formatted_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  # Crie uma interface Gradio para fazer previsões
74
  iface = gr.Interface(
75
  fn=predict_image,
76
- inputs="image",
77
- outputs="text",
78
  interpretation="default"
79
  )
80
 
 
3
  from tensorflow.keras.layers import Input, GlobalAveragePooling2D, Dense
4
  import numpy as np
5
  import gradio as gr
6
+ from PIL import Image, ImageDraw, ImageFont
7
 
8
  # Dimensões da imagem
9
  IMG_HEIGHT = 224
 
67
  # For example:
68
  # formatted_text = f"Predicted Class: {predicted_class}\nProbability: {probability:.2%}\nObject Detection: {bounding_box_coordinates}"
69
 
70
+ # Create an output image with object detection
71
+ output_image = input_image # Replace this with your object detection visualization
72
+
73
+ # Convert the output image to bytes
74
+ output_image_bytes = Image.fromarray(np.uint8(output_image * 255))
75
+
76
+ # Create an image with the label "Normal" or "Cataract" outside the image
77
+ draw = ImageDraw.Draw(output_image_bytes)
78
+ font = ImageFont.load_default() # You can customize the font and size here
79
+ label_text = f"Predicted Class: {predicted_class}"
80
+ label_size = draw.textsize(label_text, font=font)
81
+ label_position = (10, 10) # You can adjust the label position
82
+ draw.rectangle([label_position, (label_position[0] + label_size[0], label_position[1] + label_size[1])], fill="white")
83
+ draw.text(label_position, label_text, fill="black", font=font)
84
+
85
+ # Convert the image with the label to bytes
86
+ labeled_image_bytes = output_image_bytes.tobytes()
87
+
88
+ # Return both the image with object detection and the labeled image
89
+ return [labeled_image_bytes, f"Predicted Class: {predicted_class}"]
90
 
91
  # Crie uma interface Gradio para fazer previsões
92
  iface = gr.Interface(
93
  fn=predict_image,
94
+ inputs=gr.inputs.Image(label="Upload an Image", type="file"),
95
+ outputs=[gr.outputs.Image(type="pil"), gr.outputs.Text(label="Prediction", type="markdown")],
96
  interpretation="default"
97
  )
98