black formatting
This commit is contained in:
@@ -175,7 +175,9 @@ class MarkItDown:
|
||||
warn("Plugins converters are already enabled.", RuntimeWarning)
|
||||
|
||||
def convert(
|
||||
self, source: Union[str, requests.Response, Path, BufferedIOBase, TextIOBase], **kwargs: Any
|
||||
self,
|
||||
source: Union[str, requests.Response, Path, BufferedIOBase, TextIOBase],
|
||||
**kwargs: Any,
|
||||
) -> DocumentConverterResult: # TODO: deal with kwargs
|
||||
"""
|
||||
Args:
|
||||
@@ -225,7 +227,7 @@ class MarkItDown:
|
||||
|
||||
def convert_file_object(
|
||||
self, file_object: Union[BufferedIOBase, TextIOBase], **kwargs: Any
|
||||
) -> DocumentConverterResult: #TODO: deal with kwargs
|
||||
) -> DocumentConverterResult: # TODO: deal with kwargs
|
||||
# Prepare a list of extensions to try (in order of priority)
|
||||
ext = kwargs.get("file_extension")
|
||||
extensions = [ext] if ext is not None else []
|
||||
|
||||
@@ -22,7 +22,9 @@ class BingSerpConverter(DocumentConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a Bing SERP
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() not in [".html", ".htm"]:
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from typing import Any, Union
|
||||
|
||||
|
||||
class ConverterInput:
|
||||
"""
|
||||
Wrapper for inputs to converter functions.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input_type: str = "filepath",
|
||||
@@ -19,7 +21,7 @@ class ConverterInput:
|
||||
|
||||
def read_file(
|
||||
self,
|
||||
mode: str = 'rb',
|
||||
mode: str = "rb",
|
||||
encoding: Union[str, None] = None,
|
||||
) -> Any:
|
||||
if self.input_type == "object":
|
||||
|
||||
@@ -61,7 +61,7 @@ class DocumentIntelligenceConverter(DocumentConverter):
|
||||
return None
|
||||
|
||||
# Get the bytestring from the converter input
|
||||
file_obj = input.read_file(mode='rb')
|
||||
file_obj = input.read_file(mode="rb")
|
||||
file_bytes = file_obj.read()
|
||||
file_obj.close()
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ class DocxConverter(HtmlConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a DOCX
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".docx":
|
||||
|
||||
@@ -14,7 +14,9 @@ class ImageConverter(MediaConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not an image
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() not in [".jpg", ".jpeg", ".png"]:
|
||||
@@ -63,7 +65,9 @@ class ImageConverter(MediaConverter):
|
||||
text_content=md_content,
|
||||
)
|
||||
|
||||
def _get_llm_description(self, input: ConverterInput, extension, client, model, prompt=None):
|
||||
def _get_llm_description(
|
||||
self, input: ConverterInput, extension, client, model, prompt=None
|
||||
):
|
||||
if prompt is None or prompt.strip() == "":
|
||||
prompt = "Write a detailed caption for this image."
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ class Mp3Converter(WavConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a MP3
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".mp3":
|
||||
|
||||
@@ -16,7 +16,9 @@ class PdfConverter(DocumentConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a PDF
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".pdf":
|
||||
@@ -31,4 +33,3 @@ class PdfConverter(DocumentConverter):
|
||||
title=None,
|
||||
text_content=output.getvalue(),
|
||||
)
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ class PptxConverter(HtmlConverter):
|
||||
)
|
||||
return response.choices[0].message.content
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a PPTX
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".pptx":
|
||||
|
||||
@@ -23,7 +23,9 @@ class WavConverter(MediaConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a WAV
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".wav":
|
||||
|
||||
@@ -17,7 +17,9 @@ class XlsxConverter(HtmlConverter):
|
||||
):
|
||||
super().__init__(priority=priority)
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a XLSX
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".xlsx":
|
||||
@@ -44,7 +46,9 @@ class XlsConverter(HtmlConverter):
|
||||
Converts XLS files to Markdown, with each sheet presented as a separate Markdown table.
|
||||
"""
|
||||
|
||||
def convert(self, input: ConverterInput, **kwargs) -> Union[None, DocumentConverterResult]:
|
||||
def convert(
|
||||
self, input: ConverterInput, **kwargs
|
||||
) -> Union[None, DocumentConverterResult]:
|
||||
# Bail if not a XLS
|
||||
extension = kwargs.get("file_extension", "")
|
||||
if extension.lower() != ".xls":
|
||||
|
||||
Reference in New Issue
Block a user