Quellcode durchsuchen

refactor: no need to inherit in python3 clean the code (#5659)

### What problem does this PR solve?

As title

### Type of change


- [x] Refactoring

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
tags/v0.17.1
yihong vor 8 Monaten
Ursprung
Commit
4326873af6
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 1
- 1
api/db/services/llm_service.py Datei anzeigen

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

+ 1
- 1
deepdoc/parser/pdf_parser.py Datei anzeigen

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 = []

+ 1
- 1
deepdoc/parser/ppt_parser.py Datei anzeigen

from pptx import Presentation from pptx import Presentation




class RAGFlowPptParser(object):
class RAGFlowPptParser:
def __init__(self): def __init__(self):
super().__init__() super().__init__()



+ 3
- 3
deepdoc/vision/ocr.py Datei anzeigen

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!!

+ 16
- 16
deepdoc/vision/operators.py Datei anzeigen

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

+ 2
- 2
deepdoc/vision/postprocess.py Datei anzeigen

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):

+ 1
- 1
deepdoc/vision/recognizer.py Datei anzeigen

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!!

+ 1
- 1
rag/utils/azure_sas_conn.py Datei anzeigen





@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"])

+ 1
- 1
rag/utils/azure_spn_conn.py Datei anzeigen





@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"])

+ 1
- 1
rag/utils/minio_conn.py Datei anzeigen





@singleton @singleton
class RAGFlowMinio(object):
class RAGFlowMinio:
def __init__(self): def __init__(self):
self.conn = None self.conn = None
self.__open__() self.__open__()

+ 1
- 1
rag/utils/oss_conn.py Datei anzeigen





@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

+ 1
- 1
rag/utils/s3_conn.py Datei anzeigen

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

+ 1
- 1
sdk/python/ragflow_sdk/modules/base.py Datei anzeigen

# 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():

Laden…
Abbrechen
Speichern