DHEIVER commited on
Commit
ad05d92
·
1 Parent(s): 62dc535

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -23,6 +23,9 @@ id2label = {
23
 
24
  # Função para classificar a imagem
25
  def classify_image(input_image):
 
 
 
26
  # Pré-processar a imagem usando o extrator de características
27
  inputs = feature_extractor(input_image, return_tensors="pt")
28
  # Realizar inferência com o modelo
@@ -50,15 +53,13 @@ def classify_image(input_image):
50
  text = f'Classe: {predicted_class_label} ({predicted_class_prob:.2f})'
51
  text_size = cv2.getTextSize(text, font, 0.7, 2)[0]
52
  text_x = (input_image_bgr.shape[1] - text_size[0]) // 2
53
- text_y = input_image_bgr.shape[0] - 20
54
  cv2.putText(input_image_bgr, text, (text_x, text_y), font, 0.7, (255, 255, 255), 2, cv2.LINE_AA)
55
 
56
  # Converter a imagem resultante de volta para RGB (formato Pillow)
57
  result_image = cv2.cvtColor(input_image_bgr, cv2.COLOR_BGR2RGB)
58
  return result_image
59
 
60
-
61
-
62
  # Criar uma interface Gradio
63
  interface = gr.Interface(
64
  fn=classify_image,
 
23
 
24
  # Função para classificar a imagem
25
  def classify_image(input_image):
26
+ # Redimensionar a imagem de entrada para ser 2x maior
27
+ input_image = cv2.resize(input_image, None, fx=2, fy=2)
28
+
29
  # Pré-processar a imagem usando o extrator de características
30
  inputs = feature_extractor(input_image, return_tensors="pt")
31
  # Realizar inferência com o modelo
 
53
  text = f'Classe: {predicted_class_label} ({predicted_class_prob:.2f})'
54
  text_size = cv2.getTextSize(text, font, 0.7, 2)[0]
55
  text_x = (input_image_bgr.shape[1] - text_size[0]) // 2
56
+ text_y = input_image_bgr.shape[0] - 30 # Ajuste da posição vertical
57
  cv2.putText(input_image_bgr, text, (text_x, text_y), font, 0.7, (255, 255, 255), 2, cv2.LINE_AA)
58
 
59
  # Converter a imagem resultante de volta para RGB (formato Pillow)
60
  result_image = cv2.cvtColor(input_image_bgr, cv2.COLOR_BGR2RGB)
61
  return result_image
62
 
 
 
63
  # Criar uma interface Gradio
64
  interface = gr.Interface(
65
  fn=classify_image,