amaye15
commited on
Commit
·
b54bf3c
1
Parent(s):
a557518
First model version
Browse files- .gitattributes +9 -0
- .gitignore +1 -0
- adapter_config.json +3 -0
- adapter_model.safetensors +3 -0
- added_tokens.json +3 -0
- chat_template.json +3 -0
- generation_config.json +3 -0
- handler.py +58 -0
- merges.txt +0 -0
- preprocessor_config.json +3 -0
- special_tokens_map.json +3 -0
- tokenizer.json +3 -0
- tokenizer_config.json +3 -0
- vocab.json +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
chat_template.json filter=lfs diff=lfs merge=lfs -text
|
37 |
+
generation_config.json filter=lfs diff=lfs merge=lfs -text
|
38 |
+
preprocessor_config.json filter=lfs diff=lfs merge=lfs -text
|
39 |
+
tokenizer_config.json filter=lfs diff=lfs merge=lfs -text
|
40 |
+
adapter_config.json filter=lfs diff=lfs merge=lfs -text
|
41 |
+
added_tokens.json filter=lfs diff=lfs merge=lfs -text
|
42 |
+
special_tokens_map.json filter=lfs diff=lfs merge=lfs -text
|
43 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
44 |
+
vocab.json filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
*.DS*
|
adapter_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c88fb289a155188a09737629830dc32e753bb679d6bddd5f94ddf9daa1921114
|
3 |
+
size 727
|
adapter_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fc856312174dc99a4c7f88a2c54d9590a3b3f5b5a86e2728d7138c7f4758c6d5
|
3 |
+
size 74018232
|
added_tokens.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7fa54985b58718a8fdb4f4d97484c4bd908db114847675e4bf3afe3e1d5d7bd4
|
3 |
+
size 392
|
chat_template.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94174d7176c52a7192f96fc34eb2cf23c7c2059d63cdbfadca1586ba89731fb7
|
3 |
+
size 1049
|
generation_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f31bc5c808ee15908986654279dd054f3e6bd65d52f8ca7b18a2a80552e2d35b
|
3 |
+
size 215
|
handler.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from typing import Dict, Any
|
3 |
+
from PIL import Image
|
4 |
+
import base64
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
|
8 |
+
class EndpointHandler:
|
9 |
+
def __init__(self, path: str = ""):
|
10 |
+
# Import your model and processor inside the class
|
11 |
+
from colpali_engine.models import ColQwen2, ColQwen2Processor
|
12 |
+
|
13 |
+
# Load the model and processor
|
14 |
+
self.model = ColQwen2.from_pretrained(
|
15 |
+
path,
|
16 |
+
torch_dtype=torch.bfloat16,
|
17 |
+
).eval()
|
18 |
+
self.processor = ColQwen2Processor.from_pretrained(path)
|
19 |
+
|
20 |
+
# Determine the device
|
21 |
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
22 |
+
self.model.to(self.device)
|
23 |
+
|
24 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
25 |
+
# Extract images from the input data
|
26 |
+
images_data = data.get("inputs", [])
|
27 |
+
|
28 |
+
if not images_data:
|
29 |
+
return {"error": "No images provided in 'inputs'."}
|
30 |
+
|
31 |
+
# Process images
|
32 |
+
images = []
|
33 |
+
for img_data in images_data:
|
34 |
+
if isinstance(img_data, str):
|
35 |
+
try:
|
36 |
+
# Assume base64-encoded image
|
37 |
+
image_bytes = base64.b64decode(img_data)
|
38 |
+
image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
39 |
+
images.append(image)
|
40 |
+
except Exception as e:
|
41 |
+
return {"error": f"Invalid image data: {e}"}
|
42 |
+
else:
|
43 |
+
return {"error": "Images should be base64-encoded strings."}
|
44 |
+
|
45 |
+
# Prepare inputs
|
46 |
+
batch_images = self.processor.process_images(images)
|
47 |
+
|
48 |
+
# Move tensors to the device
|
49 |
+
batch_images = {k: v.to(self.device) for k, v in batch_images.items()}
|
50 |
+
|
51 |
+
# Generate embeddings
|
52 |
+
with torch.no_grad():
|
53 |
+
image_embeddings = self.model(**batch_images)
|
54 |
+
|
55 |
+
# Convert embeddings to a list
|
56 |
+
embeddings_list = image_embeddings.cpu().tolist()
|
57 |
+
|
58 |
+
return {"embeddings": embeddings_list}
|
merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
preprocessor_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5dd5968b65af7e090e399f39ae94734e400d9d71a3c82fca2720c5ee514034f3
|
3 |
+
size 568
|
special_tokens_map.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:76862e765266b85aa9459767e33cbaf13970f327a0e88d1c65846c2ddd3a1ecd
|
3 |
+
size 613
|
tokenizer.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:091aa7594dc2fcfbfa06b9e3c22a5f0562ac14f30375c13af7309407a0e67b8a
|
3 |
+
size 11420371
|
tokenizer_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:955409fb4dab09a71b957ce69f8a8185bbbd3416b9ab5a47e01221545be39c6f
|
3 |
+
size 4298
|
vocab.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910
|
3 |
+
size 2776833
|