Spaces:
Running
on
Zero
Running
on
Zero
Liam Dyer
commited on
temp
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
from marker.convert import convert_single_pdf
|
4 |
from marker.models import load_all_models
|
5 |
import surya.detection as detection
|
|
|
6 |
|
7 |
model_lst = load_all_models()
|
8 |
|
@@ -23,6 +24,30 @@ def batch_text_detection(images, model, processor, batch_size=None):
|
|
23 |
detection.batch_text_detection = batch_text_detection
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
@spaces.GPU
|
27 |
def convert(file_path):
|
28 |
print(file_path)
|
|
|
3 |
from marker.convert import convert_single_pdf
|
4 |
from marker.models import load_all_models
|
5 |
import surya.detection as detection
|
6 |
+
import surya.layout as layout
|
7 |
|
8 |
model_lst = load_all_models()
|
9 |
|
|
|
24 |
detection.batch_text_detection = batch_text_detection
|
25 |
|
26 |
|
27 |
+
def batch_layout_detection(
|
28 |
+
images, model, processor, detection_results=None, batch_size=None
|
29 |
+
):
|
30 |
+
preds, orig_sizes = layout.batch_detection(
|
31 |
+
images, model, processor, batch_size=batch_size
|
32 |
+
)
|
33 |
+
id2label = model.config.id2label
|
34 |
+
|
35 |
+
results = []
|
36 |
+
for i in range(len(images)):
|
37 |
+
result = layout.parallel_get_regions(
|
38 |
+
preds[i],
|
39 |
+
orig_sizes[i],
|
40 |
+
id2label,
|
41 |
+
detection_results[i] if detection_results else None,
|
42 |
+
)
|
43 |
+
results.append(result)
|
44 |
+
|
45 |
+
return results
|
46 |
+
|
47 |
+
|
48 |
+
layout.batch_layout_detection = batch_layout_detection
|
49 |
+
|
50 |
+
|
51 |
@spaces.GPU
|
52 |
def convert(file_path):
|
53 |
print(file_path)
|