DHEIVER commited on
Commit
daf5ee2
1 Parent(s): 8dc799b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -34,11 +34,19 @@ def classify_image(input_image):
34
  predicted_class_label = id2label.get(str(predicted_class_id), "Desconhecido")
35
  # Abrir a imagem usando PIL
36
  image = Image.fromarray(input_image.astype('uint8'))
37
- # Criar uma imagem com o r贸tulo de previs茫o sobreposta
38
- from PIL import ImageDraw, ImageFont
39
- draw = ImageDraw.Draw(image)
40
  font = ImageFont.load_default()
41
- draw.text((10, 10), f'Previs茫o: {predicted_class_label}', fill='white', font=font)
 
 
 
 
 
 
 
 
42
  # Converter a imagem resultante de volta para numpy
43
  result_image = np.array(image)
44
  return result_image
 
34
  predicted_class_label = id2label.get(str(predicted_class_id), "Desconhecido")
35
  # Abrir a imagem usando PIL
36
  image = Image.fromarray(input_image.astype('uint8'))
37
+
38
+ # Calcular as coordenadas para o texto no centro da imagem
39
+ width, height = image.size
40
  font = ImageFont.load_default()
41
+ text = f'Previs茫o: {predicted_class_label}'
42
+ text_width, text_height = draw.textsize(text, font)
43
+ x = (width - text_width) // 2
44
+ y = (height - text_height) // 2
45
+
46
+ # Criar uma imagem com o r贸tulo de previs茫o sobreposta no centro
47
+ draw = ImageDraw.Draw(image)
48
+ draw.text((x, y), text, fill='white', font=font)
49
+
50
  # Converter a imagem resultante de volta para numpy
51
  result_image = np.array(image)
52
  return result_image