Spaces:
Running
Running
Use GPU if available
Browse files
app.py
CHANGED
@@ -17,6 +17,9 @@ import easyocr
|
|
17 |
import gradio as gr
|
18 |
|
19 |
|
|
|
|
|
|
|
20 |
class MaxResize(object):
|
21 |
def __init__(self, max_size=800):
|
22 |
self.max_size = max_size
|
@@ -43,11 +46,11 @@ structure_transform = transforms.Compose([
|
|
43 |
|
44 |
# load table detection model
|
45 |
# processor = TableTransformerImageProcessor(max_size=800)
|
46 |
-
model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-detection", revision="no_timm")
|
47 |
|
48 |
# load table structure recognition model
|
49 |
# structure_processor = TableTransformerImageProcessor(max_size=1000)
|
50 |
-
structure_model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-structure-recognition-v1.1-all")
|
51 |
|
52 |
# load EasyOCR reader
|
53 |
reader = easyocr.Reader(['en'])
|
@@ -145,7 +148,7 @@ def visualize_detected_tables(img, det_tables):
|
|
145 |
def detect_and_crop_table(image):
|
146 |
# prepare image for the model
|
147 |
# pixel_values = processor(image, return_tensors="pt").pixel_values
|
148 |
-
pixel_values = detection_transform(image).unsqueeze(0)
|
149 |
|
150 |
# forward pass
|
151 |
with torch.no_grad():
|
@@ -169,7 +172,7 @@ def detect_and_crop_table(image):
|
|
169 |
def recognize_table(image):
|
170 |
# prepare image for the model
|
171 |
# pixel_values = structure_processor(images=image, return_tensors="pt").pixel_values
|
172 |
-
pixel_values = structure_transform(image).unsqueeze(0)
|
173 |
|
174 |
# forward pass
|
175 |
with torch.no_grad():
|
|
|
17 |
import gradio as gr
|
18 |
|
19 |
|
20 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
21 |
+
|
22 |
+
|
23 |
class MaxResize(object):
|
24 |
def __init__(self, max_size=800):
|
25 |
self.max_size = max_size
|
|
|
46 |
|
47 |
# load table detection model
|
48 |
# processor = TableTransformerImageProcessor(max_size=800)
|
49 |
+
model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-detection", revision="no_timm").to(device)
|
50 |
|
51 |
# load table structure recognition model
|
52 |
# structure_processor = TableTransformerImageProcessor(max_size=1000)
|
53 |
+
structure_model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-structure-recognition-v1.1-all").to(device)
|
54 |
|
55 |
# load EasyOCR reader
|
56 |
reader = easyocr.Reader(['en'])
|
|
|
148 |
def detect_and_crop_table(image):
|
149 |
# prepare image for the model
|
150 |
# pixel_values = processor(image, return_tensors="pt").pixel_values
|
151 |
+
pixel_values = detection_transform(image).unsqueeze(0).to(device)
|
152 |
|
153 |
# forward pass
|
154 |
with torch.no_grad():
|
|
|
172 |
def recognize_table(image):
|
173 |
# prepare image for the model
|
174 |
# pixel_values = structure_processor(images=image, return_tensors="pt").pixel_values
|
175 |
+
pixel_values = structure_transform(image).unsqueeze(0).to(device)
|
176 |
|
177 |
# forward pass
|
178 |
with torch.no_grad():
|