Skip to content

Commit 5d5302c

Browse files
committed
fix axtract typing
1 parent 5ec9a97 commit 5d5302c

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

src/axiomatic/axtract/axtract_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .relation_graph import generate_relation_graph
2-
from .models import EquationExtractionResponse
2+
from .. import EquationExtractionResponse
33
import os
44
import re
55

src/axiomatic/axtract/interactive_table.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from IPython.display import display # type: ignore
33
import json # type: ignore
44
import os # type: ignore
5-
from .axtract_report import EquationExtractionResponse
6-
from .models import VariableRequirement
5+
from .. import EquationExtractionResponse, VariableRequirement
76

87

98
def _find_symbol(name, variable_dict):

src/axiomatic/axtract/models.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/axiomatic/axtract/relation_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List
2-
from .models import EquationExtraction
2+
from .. import EquationExtraction
33
from pyvis.network import Network # type: ignore
44

55

src/axiomatic/client.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
import requests
33
import os
44
import time
5+
import json
56
from typing import Dict, List, Union, Optional
67

78
from .base_client import BaseClient, AsyncBaseClient
8-
from . import ParseResponse
9-
from .axtract.models import EquationExtractionResponse
10-
9+
from . import ParseResponse, EquationProcessingResponse, EquationExtractionResponse
1110

1211
class Axiomatic(BaseClient):
1312
def __init__(self, *args, **kwargs):
@@ -17,6 +16,7 @@ def __init__(self, *args, **kwargs):
1716

1817
self.document_helper = DocumentHelper(self)
1918
self.tools_helper = ToolsHelper(self)
19+
self.axtract_helper = AxtractHelper(self)
2020

2121

2222
class AxtractHelper:
@@ -38,6 +38,7 @@ def analyze_equations(
3838
url_path: Optional[str] = None,
3939
parsed_paper: Optional[ParseResponse] = None,
4040
) -> Optional[EquationExtractionResponse]:
41+
response : EquationExtractionResponse | EquationProcessingResponse
4142
if file_path:
4243
with open(file_path, "rb") as file:
4344
response = self._ax_client.document.equation.from_pdf(document=file)
@@ -47,7 +48,7 @@ def analyze_equations(
4748

4849
response = self._ax_client.document.equation.from_pdf(document=url_path)
4950
elif parsed_paper:
50-
response = self._ax_client.document.equation.process(**parsed_paper)
51+
response = self._ax_client.document.equation.process(**parsed_paper.model_dump())
5152
else:
5253
print("Please provide either a file path or a URL to analyze.")
5354
return None
@@ -135,13 +136,19 @@ def navigate_image(change):
135136
def save_parsed_pdf(self, response: ParseResponse, path: str):
136137
"""Save a parsed PDF response to a file."""
137138
os.makedirs(path, exist_ok=True)
139+
with open(os.path.join(path, "text.md"), "w") as f:
140+
f.write(response.markdown)
141+
138142
if response.images:
139143
for img_name, img in response.images.items():
140144
with open(os.path.join(path, f"{img_name}.png"), "wb") as f:
141145
f.write(base64.b64decode(img))
142146

143-
with open(os.path.join(path, "text.md"), "w") as f:
144-
f.write(response.markdown)
147+
with open(os.path.join(path, "interline_equations.json"), "w") as f:
148+
json.dump(response.interline_equations, f)
149+
150+
with open(os.path.join(path, "inline_equations.json"), "w") as f:
151+
json.dump(response.inline_equations, f)
145152

146153
def load_parsed_pdf(self, path: str) -> ParseResponse:
147154
"""Load a parsed PDF response from a file."""
@@ -154,7 +161,18 @@ def load_parsed_pdf(self, path: str) -> ParseResponse:
154161
with open(os.path.join(path, img_name), "rb") as img_file:
155162
images[img_name] = base64.b64encode(img_file.read()).decode("utf-8")
156163

157-
return ParseResponse(markdown=markdown, images=images)
164+
with open(os.path.join(path, "interline_equations.json"), "r") as f:
165+
interline_equations = json.load(f)
166+
167+
with open(os.path.join(path, "inline_equations.json"), "r") as f:
168+
inline_equations = json.load(f)
169+
170+
return ParseResponse(
171+
markdown=markdown,
172+
images=images,
173+
interline_equations=interline_equations,
174+
inline_equations=inline_equations,
175+
)
158176

159177

160178
class ToolsHelper:

0 commit comments

Comments
 (0)