amaye15 commited on
Commit
4e7495e
Β·
1 Parent(s): 8455e47

Restructure repo

Browse files
README.md CHANGED
@@ -1,5 +1,3 @@
1
  ---
2
  license: mit
3
- tags:
4
- - custom-handler
5
  ---
 
1
  ---
2
  license: mit
 
 
3
  ---
handler.py CHANGED
@@ -7,31 +7,22 @@ from io import BytesIO
7
 
8
  class EndpointHandler:
9
  """
10
- A handler class for processing image data and generating embeddings using a specified model and processor.
11
 
12
  Attributes:
13
- model (:obj:):
14
- The pre-trained model used for generating embeddings.
15
- processor (:obj:):
16
- The pre-trained processor used to process images before model inference.
17
- device (:obj:):
18
- The device (CPU or CUDA) used to run model inference.
19
- default_batch_size (:obj:int:):
20
- The default batch size for processing images in batches.
21
  """
22
 
23
- def __init__(self, path: str = "", default_batch_size: int = 4):
24
  """
25
  Initializes the EndpointHandler with a specified model path and default batch size.
26
 
27
  Args:
28
- path (:obj:`str`, optional):
29
- Path to the pre-trained model and processor.
30
- default_batch_size (:obj:`int`, optional):
31
- Default batch size for image processing.
32
-
33
- Return:
34
- None
35
  """
36
  from colpali_engine.models import ColQwen2, ColQwen2Processor
37
 
@@ -50,11 +41,10 @@ class EndpointHandler:
50
  Processes a batch of images and generates embeddings.
51
 
52
  Args:
53
- images (:obj:`List[Image.Image]`):
54
- List of images to process.
55
 
56
- Return:
57
- A :obj:`List[List[float]]`. A list of embeddings for each image, where each embedding is a list of floats.
58
  """
59
  batch_images = self.processor.process_images(images)
60
  batch_images = {k: v.to(self.device) for k, v in batch_images.items()}
@@ -69,12 +59,10 @@ class EndpointHandler:
69
  Processes input data containing base64-encoded images, decodes them, and generates embeddings.
70
 
71
  Args:
72
- data (:obj:`Dict[str, Any]`):
73
- Includes the input data and the parameters for the inference, such as "inputs" containing a list of base64-encoded images and an optional "batch_size".
74
 
75
- Return:
76
- A :obj:`dict`. The object returned should be a dict like {"embeddings": [[0.6331314444541931, 0.8802216053009033, ..., -0.7866355180740356]]} containing:
77
- - "embeddings": A list of lists, where each inner list is a set of floats corresponding to the embeddings of each image.
78
  """
79
  images_data = data.get("inputs", [])
80
  batch_size = data.get("batch_size", self.default_batch_size)
 
7
 
8
  class EndpointHandler:
9
  """
10
+ A handler class for processing image data, generating embeddings using a specified model and processor.
11
 
12
  Attributes:
13
+ model: The pre-trained model used for generating embeddings.
14
+ processor: The pre-trained processor used to process images before model inference.
15
+ device: The device (CPU or CUDA) used to run model inference.
16
+ default_batch_size: The default batch size for processing images in batches.
 
 
 
 
17
  """
18
 
19
+ def __init__(self, path: str = "./model", default_batch_size: int = 4):
20
  """
21
  Initializes the EndpointHandler with a specified model path and default batch size.
22
 
23
  Args:
24
+ path (str): Path to the pre-trained model and processor.
25
+ default_batch_size (int): Default batch size for image processing.
 
 
 
 
 
26
  """
27
  from colpali_engine.models import ColQwen2, ColQwen2Processor
28
 
 
41
  Processes a batch of images and generates embeddings.
42
 
43
  Args:
44
+ images (List[Image.Image]): List of images to process.
 
45
 
46
+ Returns:
47
+ List[List[float]]: List of embeddings for each image.
48
  """
49
  batch_images = self.processor.process_images(images)
50
  batch_images = {k: v.to(self.device) for k, v in batch_images.items()}
 
59
  Processes input data containing base64-encoded images, decodes them, and generates embeddings.
60
 
61
  Args:
62
+ data (Dict[str, Any]): Dictionary containing input images and optional batch size.
 
63
 
64
+ Returns:
65
+ Dict[str, Any]: Dictionary containing generated embeddings or error messages.
 
66
  """
67
  images_data = data.get("inputs", [])
68
  batch_size = data.get("batch_size", self.default_batch_size)
adapter_config.json β†’ model/adapter_config.json RENAMED
File without changes
adapter_model.safetensors β†’ model/adapter_model.safetensors RENAMED
File without changes
added_tokens.json β†’ model/added_tokens.json RENAMED
File without changes
chat_template.json β†’ model/chat_template.json RENAMED
File without changes
generation_config.json β†’ model/generation_config.json RENAMED
File without changes
merges.txt β†’ model/merges.txt RENAMED
File without changes
preprocessor_config.json β†’ model/preprocessor_config.json RENAMED
File without changes
special_tokens_map.json β†’ model/special_tokens_map.json RENAMED
File without changes
tokenizer.json β†’ model/tokenizer.json RENAMED
File without changes
tokenizer_config.json β†’ model/tokenizer_config.json RENAMED
File without changes
vocab.json β†’ model/vocab.json RENAMED
File without changes