-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a571886
commit f4cd1c4
Showing
11 changed files
with
116 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
from typing import List | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class ConverterConfig(BaseModel): | ||
filepath: str | ||
page_range: List[int] | None = None | ||
|
||
|
||
class BaseConverter: | ||
def __init__(self, config: ConverterConfig): | ||
self.config = config | ||
def __init__(self, config: Optional[BaseModel] = None): | ||
if config: | ||
for k in config.model_fields: | ||
setattr(self, k, config[k]) | ||
|
||
def __call__(self): | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class BaseProcessor: | ||
pass | ||
def __init__(self, config: Optional[BaseModel] = None): | ||
if config: | ||
for k in config.model_fields: | ||
setattr(self, k, config[k]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from marker.v2.processors import BaseProcessor | ||
|
||
|
||
class EquationProcessor(BaseProcessor): | ||
block_type = "Equation" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from marker.v2.processors import BaseProcessor | ||
|
||
|
||
class TableProcessor(BaseProcessor): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import tempfile | ||
|
||
import datasets | ||
import pytest | ||
from surya.model.layout.model import load_model | ||
from surya.model.layout.processor import load_processor | ||
|
||
from marker.v2.builders.document import DocumentBuilder | ||
from marker.v2.builders.layout import LayoutBuilder | ||
from marker.v2.providers.pdf import PdfProvider | ||
from marker.v2.schema.config.pdf import PdfProviderConfig | ||
from marker.v2.schema.document import Document | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def layout_model(): | ||
layout_model = load_model() | ||
layout_model.processor = load_processor() | ||
yield layout_model | ||
del layout_model | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def pdf_document(request, layout_model) -> Document: | ||
marker = request.node.get_closest_marker("filename") | ||
if marker is None: | ||
filename = "adversarial.pdf" | ||
else: | ||
filename = marker.args[0] | ||
dataset = datasets.load_dataset("datalab-to/pdfs", split="train") | ||
idx = dataset['filename'].index(filename) | ||
|
||
temp_pdf = tempfile.NamedTemporaryFile(suffix=".pdf") | ||
temp_pdf.write(dataset['pdf'][idx]) | ||
temp_pdf.flush() | ||
|
||
provider = PdfProvider(temp_pdf.name, PdfProviderConfig()) | ||
layout_builder = LayoutBuilder(layout_model) | ||
builder = DocumentBuilder() | ||
document = builder(provider, layout_builder) | ||
return document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters