Skip to content

Commit e7157f5

Browse files
committed
Fix pip package #55
1 parent 3f667d2 commit e7157f5

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

clip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define STB_IMAGE_IMPLEMENTATION
1414
#include "stb_image.h"
1515

16-
#define CLIP_DEBUG
16+
// #define CLIP_DEBUG
1717

1818
// utility function for a workaround until https://github.com/ggerganov/ggml/issues/260 is resolved
1919
// after that, remove this and use the mechanism implemented in GGML directly

examples/python_bindings/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,27 @@ def tokenize(self, text: str) -> List[int]:
6767

6868
```python
6969
def encode_text(
70-
self, tokens: List[int], n_threads: int = os.cpu_count()
70+
self, tokens: List[int], n_threads: int = os.cpu_count(), normalize: bool = True
7171
) -> List[float]:
7272
```
7373

7474
- **Description**: Encodes a list of token IDs into a text embedding.
7575
- `tokens` (List[int]): A list of token IDs obtained through tokenization.
7676
- `n_threads` (int, optional): The number of CPU threads to use for encoding (default is the number of CPU cores).
77+
- `normalize` (bool, optional): Whether or not to normalize the output vector (default is `True`).
7778

7879
#### 5. `load_preprocess_encode_image`
7980

8081
```python
8182
def load_preprocess_encode_image(
82-
self, image_path: str, n_threads: int = os.cpu_count()
83+
self, image_path: str, n_threads: int = os.cpu_count(), normalize: bool = True
8384
) -> List[float]:
8485
```
8586

8687
- **Description**: Loads an image, preprocesses it, and encodes it into an image embedding.
8788
- `image_path` (str): The path to the image file to be encoded.
8889
- `n_threads` (int, optional): The number of CPU threads to use for encoding (default is the number of CPU cores).
90+
- `normalize` (bool, optional): Whether or not to normalize the output vector (default is `True`).
8991

9092
#### 6. `calculate_similarity`
9193

examples/python_bindings/clip_cpp/clip.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
# Note: Pass -DBUILD_SHARED_LIBS=ON to cmake to create the shared library file
66

7-
# Load the shared library
8-
path_to_dll = os.environ.get(
9-
"CLIP_DLL", os.path.join(os.path.abspath(os.path.dirname(__file__)), "libclip.so")
10-
)
7+
cur_dir = os.getcwd()
8+
this_dir = os.path.abspath(os.path.dirname(__file__))
119

12-
clip_lib = ctypes.CDLL(path_to_dll)
10+
# Load the shared library
11+
path_to_dll = os.environ.get("CLIP_DLL", this_dir)
12+
os.chdir(path_to_dll)
13+
ggml_lib = ctypes.CDLL("./libggml.so")
14+
clip_lib = ctypes.CDLL("./libclip.so")
15+
os.chdir(cur_dir)
1316

1417

1518
# Define the ctypes structures
@@ -278,7 +281,7 @@ def encode_text(
278281
return [txt_vec[i] for i in range(self.vec_dim)]
279282

280283
def load_preprocess_encode_image(
281-
self, image_path: str, n_threads: int = os.cpu_count(), normalize: bool = true
284+
self, image_path: str, n_threads: int = os.cpu_count(), normalize: bool = True
282285
) -> List[float]:
283286
image_ptr = make_clip_image_u8()
284287
if not clip_image_load_from_file(image_path.encode("utf8"), image_ptr):

examples/python_bindings/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[tool.poetry]
22
name = "clip_cpp"
3-
version = "0.2.0"
3+
version = "0.3.5"
44
description = "CLIP inference with no big dependencies as PyTorch, TensorFlow, Numpy"
55
authors = ["Yusuf Sarıgöz <[email protected]>"]
66
packages = [
77
{include = "clip_cpp"},
88
]
99
include = [
10-
{path = "clip_cpp/libclip.so"}
10+
{path = "clip_cpp/*.so"}
1111
]
1212

1313
readme = "README.md"

0 commit comments

Comments
 (0)