kebson commited on
Commit
e6d8b93
·
verified ·
1 Parent(s): a26641b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -11,7 +11,7 @@ from transformers import DetrImageProcessor, TableTransformerForObjectDetection
11
  # ===============================
12
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
13
 
14
- # Modèle de détection de tableau
15
  det_processor = DetrImageProcessor.from_pretrained(
16
  "microsoft/table-transformer-detection"
17
  )
@@ -19,7 +19,7 @@ det_model = TableTransformerForObjectDetection.from_pretrained(
19
  "microsoft/table-transformer-detection"
20
  ).to(DEVICE)
21
 
22
- # Modèle de reconnaissance de structure (cellules)
23
  struct_processor = DetrImageProcessor.from_pretrained(
24
  "microsoft/table-transformer-structure-recognition"
25
  )
@@ -72,8 +72,9 @@ def extract_description(image_pil):
72
 
73
  # ---- Redimensionner le tableau pour la structure ----
74
  max_size = 1024
75
- scale = max_size / max(table_img.shape[:2])
76
- new_w, new_h = int(table_img.shape[1]*scale), int(table_img.shape[0]*scale)
 
77
  table_resized = cv2.resize(table_img, (new_w, new_h))
78
 
79
  # ---- Structure du tableau ----
@@ -83,7 +84,7 @@ def extract_description(image_pil):
83
 
84
  results = struct_processor.post_process_object_detection(
85
  outputs,
86
- threshold=0.5, # seuil plus bas pour capturer plus de cellules
87
  target_sizes=[table_resized.shape[:2]]
88
  )[0]
89
 
 
11
  # ===============================
12
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
13
 
14
+ # Détection de tableau
15
  det_processor = DetrImageProcessor.from_pretrained(
16
  "microsoft/table-transformer-detection"
17
  )
 
19
  "microsoft/table-transformer-detection"
20
  ).to(DEVICE)
21
 
22
+ # Structure (cellules)
23
  struct_processor = DetrImageProcessor.from_pretrained(
24
  "microsoft/table-transformer-structure-recognition"
25
  )
 
72
 
73
  # ---- Redimensionner le tableau pour la structure ----
74
  max_size = 1024
75
+ scale = max(table_img.shape[:2]) / max_size
76
+ new_w = int(table_img.shape[1] / scale)
77
+ new_h = int(table_img.shape[0] / scale)
78
  table_resized = cv2.resize(table_img, (new_w, new_h))
79
 
80
  # ---- Structure du tableau ----
 
84
 
85
  results = struct_processor.post_process_object_detection(
86
  outputs,
87
+ threshold=0.5, # seuil abaissé pour capturer plus de cellules
88
  target_sizes=[table_resized.shape[:2]]
89
  )[0]
90