### What problem does this PR solve? As title ### Type of change - [x] Refactoring Signed-off-by: yihong0618 <zouzou0208@gmail.com>tags/v0.17.1
| return list(objs) | return list(objs) | ||||
| class LLMBundle(object): | |||||
| class LLMBundle: | |||||
| def __init__(self, tenant_id, llm_type, llm_name=None, lang="Chinese"): | def __init__(self, tenant_id, llm_type, llm_name=None, lang="Chinese"): | ||||
| self.tenant_id = tenant_id | self.tenant_id = tenant_id | ||||
| self.llm_type = llm_type | self.llm_type = llm_type |
| return poss | return poss | ||||
| class PlainParser(object): | |||||
| class PlainParser: | |||||
| def __call__(self, filename, from_page=0, to_page=100000, **kwargs): | def __call__(self, filename, from_page=0, to_page=100000, **kwargs): | ||||
| self.outlines = [] | self.outlines = [] | ||||
| lines = [] | lines = [] |
| from pptx import Presentation | from pptx import Presentation | ||||
| class RAGFlowPptParser(object): | |||||
| class RAGFlowPptParser: | |||||
| def __init__(self): | def __init__(self): | ||||
| super().__init__() | super().__init__() | ||||
| return loaded_model | return loaded_model | ||||
| class TextRecognizer(object): | |||||
| class TextRecognizer: | |||||
| def __init__(self, model_dir): | def __init__(self, model_dir): | ||||
| self.rec_image_shape = [int(v) for v in "3, 48, 320".split(",")] | self.rec_image_shape = [int(v) for v in "3, 48, 320".split(",")] | ||||
| self.rec_batch_num = 16 | self.rec_batch_num = 16 | ||||
| return rec_res, time.time() - st | return rec_res, time.time() - st | ||||
| class TextDetector(object): | |||||
| class TextDetector: | |||||
| def __init__(self, model_dir): | def __init__(self, model_dir): | ||||
| pre_process_list = [{ | pre_process_list = [{ | ||||
| 'DetResizeForTest': { | 'DetResizeForTest': { | ||||
| return dt_boxes, time.time() - st | return dt_boxes, time.time() - st | ||||
| class OCR(object): | |||||
| class OCR: | |||||
| def __init__(self, model_dir=None): | def __init__(self, model_dir=None): | ||||
| """ | """ | ||||
| If you have trouble downloading HuggingFace models, -_^ this might help!! | If you have trouble downloading HuggingFace models, -_^ this might help!! |
| from PIL import Image | from PIL import Image | ||||
| class DecodeImage(object): | |||||
| class DecodeImage: | |||||
| """ decode image """ | """ decode image """ | ||||
| def __init__(self, | def __init__(self, | ||||
| return data | return data | ||||
| class StandardizeImage(object): | |||||
| class StandardizeImag: | |||||
| """normalize image | """normalize image | ||||
| Args: | Args: | ||||
| mean (list): im - mean | mean (list): im - mean | ||||
| return im, im_info | return im, im_info | ||||
| class NormalizeImage(object): | |||||
| class NormalizeImage: | |||||
| """ normalize image such as subtract mean, divide std | """ normalize image such as subtract mean, divide std | ||||
| """ | """ | ||||
| return data | return data | ||||
| class ToCHWImage(object): | |||||
| class ToCHWImage: | |||||
| """ convert hwc image to chw image | """ convert hwc image to chw image | ||||
| """ | """ | ||||
| return data | return data | ||||
| class KeepKeys(object): | |||||
| class KeepKeys: | |||||
| def __init__(self, keep_keys, **kwargs): | def __init__(self, keep_keys, **kwargs): | ||||
| self.keep_keys = keep_keys | self.keep_keys = keep_keys | ||||
| return data_list | return data_list | ||||
| class Pad(object): | |||||
| class Pad: | |||||
| def __init__(self, size=None, size_div=32, **kwargs): | def __init__(self, size=None, size_div=32, **kwargs): | ||||
| if size is not None and not isinstance(size, (int, list, tuple)): | if size is not None and not isinstance(size, (int, list, tuple)): | ||||
| raise TypeError("Type of target_size is invalid. Now is {}".format( | raise TypeError("Type of target_size is invalid. Now is {}".format( | ||||
| return data | return data | ||||
| class LinearResize(object): | |||||
| class LinearResize: | |||||
| """resize image by target_size and max_size | """resize image by target_size and max_size | ||||
| Args: | Args: | ||||
| target_size (int): the target size of image | target_size (int): the target size of image | ||||
| return im_scale_y, im_scale_x | return im_scale_y, im_scale_x | ||||
| class Resize(object): | |||||
| class Resize: | |||||
| def __init__(self, size=(640, 640), **kwargs): | def __init__(self, size=(640, 640), **kwargs): | ||||
| self.size = size | self.size = size | ||||
| return data | return data | ||||
| class DetResizeForTest(object): | |||||
| class DetResizeForTest: | |||||
| def __init__(self, **kwargs): | def __init__(self, **kwargs): | ||||
| super(DetResizeForTest, self).__init__() | super(DetResizeForTest, self).__init__() | ||||
| self.resize_type = 0 | self.resize_type = 0 | ||||
| return img, [ratio_h, ratio_w] | return img, [ratio_h, ratio_w] | ||||
| class E2EResizeForTest(object): | |||||
| class E2EResizeForTest: | |||||
| def __init__(self, **kwargs): | def __init__(self, **kwargs): | ||||
| super(E2EResizeForTest, self).__init__() | super(E2EResizeForTest, self).__init__() | ||||
| self.max_side_len = kwargs['max_side_len'] | self.max_side_len = kwargs['max_side_len'] | ||||
| return im, (ratio_h, ratio_w) | return im, (ratio_h, ratio_w) | ||||
| class KieResize(object): | |||||
| class KieResize: | |||||
| def __init__(self, **kwargs): | def __init__(self, **kwargs): | ||||
| super(KieResize, self).__init__() | super(KieResize, self).__init__() | ||||
| self.max_side, self.min_side = kwargs['img_scale'][0], kwargs[ | self.max_side, self.min_side = kwargs['img_scale'][0], kwargs[ | ||||
| return points | return points | ||||
| class SRResize(object): | |||||
| class SRResize: | |||||
| def __init__(self, | def __init__(self, | ||||
| imgH=32, | imgH=32, | ||||
| imgW=128, | imgW=128, | ||||
| return data | return data | ||||
| class ResizeNormalize(object): | |||||
| class ResizeNormalize: | |||||
| def __init__(self, size, interpolation=Image.BICUBIC): | def __init__(self, size, interpolation=Image.BICUBIC): | ||||
| self.size = size | self.size = size | ||||
| self.interpolation = interpolation | self.interpolation = interpolation | ||||
| return img_numpy | return img_numpy | ||||
| class GrayImageChannelFormat(object): | |||||
| class GrayImageChannelFormat: | |||||
| """ | """ | ||||
| format gray scale image's channel: (3,h,w) -> (1,h,w) | format gray scale image's channel: (3,h,w) -> (1,h,w) | ||||
| Args: | Args: | ||||
| return data | return data | ||||
| class Permute(object): | |||||
| class Permute: | |||||
| """permute image | """permute image | ||||
| Args: | Args: | ||||
| to_bgr (bool): whether convert RGB to BGR | to_bgr (bool): whether convert RGB to BGR | ||||
| return im, im_info | return im, im_info | ||||
| class PadStride(object): | |||||
| class PadStride: | |||||
| """ padding image for model with FPN, instead PadBatch(pad_to_stride) in original config | """ padding image for model with FPN, instead PadBatch(pad_to_stride) in original config | ||||
| Args: | Args: | ||||
| stride (bool): model with FPN need image shape % stride == 0 | stride (bool): model with FPN need image shape % stride == 0 |
| return module_class(**config) | return module_class(**config) | ||||
| class DBPostProcess(object): | |||||
| class DBPostProcess: | |||||
| """ | """ | ||||
| The post process for Differentiable Binarization (DB). | The post process for Differentiable Binarization (DB). | ||||
| """ | """ | ||||
| return boxes_batch | return boxes_batch | ||||
| class BaseRecLabelDecode(object): | |||||
| class BaseRecLabelDecode: | |||||
| """ Convert between text-label and text-index """ | """ Convert between text-label and text-index """ | ||||
| def __init__(self, character_dict_path=None, use_space_char=False): | def __init__(self, character_dict_path=None, use_space_char=False): |
| from . import operators | from . import operators | ||||
| from .ocr import load_model | from .ocr import load_model | ||||
| class Recognizer(object): | |||||
| class Recognizer: | |||||
| def __init__(self, label_list, task_name, model_dir=None): | def __init__(self, label_list, task_name, model_dir=None): | ||||
| """ | """ | ||||
| If you have trouble downloading HuggingFace models, -_^ this might help!! | If you have trouble downloading HuggingFace models, -_^ this might help!! |
| @singleton | @singleton | ||||
| class RAGFlowAzureSasBlob(object): | |||||
| class RAGFlowAzureSasBlob: | |||||
| def __init__(self): | def __init__(self): | ||||
| self.conn = None | self.conn = None | ||||
| self.container_url = os.getenv('CONTAINER_URL', settings.AZURE["container_url"]) | self.container_url = os.getenv('CONTAINER_URL', settings.AZURE["container_url"]) |
| @singleton | @singleton | ||||
| class RAGFlowAzureSpnBlob(object): | |||||
| class RAGFlowAzureSpnBlob: | |||||
| def __init__(self): | def __init__(self): | ||||
| self.conn = None | self.conn = None | ||||
| self.account_url = os.getenv('ACCOUNT_URL', settings.AZURE["account_url"]) | self.account_url = os.getenv('ACCOUNT_URL', settings.AZURE["account_url"]) |
| @singleton | @singleton | ||||
| class RAGFlowMinio(object): | |||||
| class RAGFlowMinio: | |||||
| def __init__(self): | def __init__(self): | ||||
| self.conn = None | self.conn = None | ||||
| self.__open__() | self.__open__() |
| @singleton | @singleton | ||||
| class RAGFlowOSS(object): | |||||
| class RAGFlowOSS: | |||||
| def __init__(self): | def __init__(self): | ||||
| self.conn = None | self.conn = None | ||||
| self.oss_config = settings.OSS | self.oss_config = settings.OSS |
| from rag import settings | from rag import settings | ||||
| @singleton | @singleton | ||||
| class RAGFlowS3(object): | |||||
| class RAGFlowS3: | |||||
| def __init__(self): | def __init__(self): | ||||
| self.conn = None | self.conn = None | ||||
| self.s3_config = settings.S3 | self.s3_config = settings.S3 |
| # limitations under the License. | # limitations under the License. | ||||
| # | # | ||||
| class Base(object): | |||||
| class Base: | |||||
| def __init__(self, rag, res_dict): | def __init__(self, rag, res_dict): | ||||
| self.rag = rag | self.rag = rag | ||||
| for k, v in res_dict.items(): | for k, v in res_dict.items(): |