-
Notifications
You must be signed in to change notification settings - Fork 16.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
Showing
6 changed files
with
29 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
from typing import Any, Iterator, List | ||
from __future__ import annotations | ||
|
||
from langchain_core.documents.base import Document | ||
from pathlib import Path | ||
from typing import Any, Union | ||
|
||
from langchain.document_loaders import Blob | ||
from langchain.document_loaders.base import BaseLoader | ||
from langchain.document_loaders.blob_loaders import FileSystemBlobLoader | ||
from langchain.document_loaders.generic import GenericLoader | ||
from langchain.document_loaders.parsers.audio import AzureSpeechServiceParser | ||
|
||
|
||
class AzureSpeechServiceLoader(BaseLoader): | ||
def __init__(self, file_path: str, **kwargs: Any) -> None: | ||
"""Initialize with file path.""" | ||
super().__init__() | ||
|
||
self.file_path = file_path | ||
self.parser = AzureSpeechServiceParser(**kwargs) | ||
|
||
def load(self) -> List[Document]: | ||
"""Eagerly load the content.""" | ||
return list(self.lazy_load()) | ||
|
||
def lazy_load( | ||
self, | ||
) -> Iterator[Document]: | ||
"""Lazily lod documents.""" | ||
blob = Blob.from_path(self.file_path) | ||
return iter(self.parser.parse(blob)) | ||
class AzureSpeechServiceLoader(GenericLoader): | ||
@classmethod | ||
def from_path( | ||
cls, path: Union[str, Path], **kwargs: Any | ||
) -> AzureSpeechServiceLoader: | ||
path = path if isinstance(path, Path) else Path(path) | ||
if path.is_file(): | ||
loader_params: dict = {"glob": path.name} | ||
path = path.parent | ||
else: | ||
loader_params = {} | ||
loader = FileSystemBlobLoader(path, **loader_params) | ||
parser = AzureSpeechServiceParser(**kwargs) | ||
return cls(loader, parser) |
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
File renamed without changes.
Binary file not shown.