File size: 1,048 Bytes
145d936
 
658b64e
 
9bdea1a
145d936
a9d0472
 
145d936
9bdea1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145d936
 
a9d0472
 
 
 
145d936
 
 
 
 
 
 
 
 
 
 
 
61f316a
145d936
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import spaces
import gradio as gr
from marker.convert import convert_single_pdf
from marker.models import load_all_models
import surya.detection as detection

model_lst = load_all_models()


# Monkey patch to prevent spawning processes
def batch_text_detection(images, model, processor, batch_size=None):
    preds, orig_sizes = detection.batch_detection(
        images, model, processor, batch_size=batch_size
    )
    results = []
    for i in range(len(images)):
        result = detection.parallel_get_lines(preds[i], orig_sizes[i])
        results.append(result)

    return results


detection.batch_text_detection = batch_text_detection


@spaces.GPU
def convert(file_path):
    print(file_path)
    global model_lst

    full_text, images = convert_single_pdf(
        file_path,
        model_lst,
        max_pages=None,
        langs=None,
        batch_multiplier=16,
    )

    return full_text


gr.Interface(
    convert,
    inputs=gr.File(label="PDF file", type="filepath"),
    outputs=gr.Markdown(label="Markdown"),
).launch()