Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add embed_anything module and update pyproject.toml #8

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ license = {file = "LICENSE"}

[tool.maturin]
features = ["pyo3/extension-module"]

include = [{path = "lib/*.dll", format = ["sdist", "wheel"]}]
python-source = "python"
[project.urls]
Homepage = "https://github.com/StarlightSearch/EmbedAnything/tree/main"
5 changes: 5 additions & 0 deletions python/embed_anything/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .embed_anything import *

__doc__ = embed_anything.__doc__
if hasattr(embed_anything, "__all__"):
__all__ = embed_anything.__all__
47 changes: 47 additions & 0 deletions python/embed_anything/embed_anything.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from .embed_anything import *

def embed_query(query: list[str], embeder: str) -> list[EmbedData]:
"""
Embeds the given query and returns an EmbedData object.

### Arguments:
- `query`: The query to embed.
- `embeder`: The name of the embedding model to use. Choose between "OpenAI" and "AllMiniLmL12V2"

### Returns:
- An EmbedData object.
"""
def embed_file(file_path: str, embeder: str) -> list[EmbedData]:
"""
Embeds the file at the given path and returns a list of EmbedData objects.

### Arguments:
- `file_path`: The path to the file to embed.
- `embeder`: The name of the embedding model to use. Choose between "OpenAI" and "AllMiniLmL12V2"

### Returns:
- A list of EmbedData objects.
"""

def embed_directory(file_path: str, embeder: str) -> list[EmbedData]:
"""
Embeds all the files in the given directory and returns a list of EmbedData objects.

### Arguments:
- `file_path`: The path to the directory containing the files to embed.
- `embeder`: The name of the embedding model to use. Choose between "OpenAI" and "AllMiniLmL12V2"

### Returns:
- A list of EmbedData objects.
"""

class EmbedData:
"""
Represents the data of an embedded file.

### Attributes:
- `embedding`: The embedding of the file.
- `text`: The text for which the embedding is generated for.
"""
embedding: list[float]
text: str
Binary file added python/embed_anything/libiomp5md.dll
Binary file not shown.
Empty file added python/embed_anything/py.typed
Empty file.
11 changes: 1 addition & 10 deletions test.py → python/embed_anything/test.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import os
import numpy as np
# os.add_dll_directory(r'D:\test')
from embed_anything import EmbedData
import embed_anything
from embed_anything import EmbedData
from PIL import Image
import time

# data:list[EmbedData] = embed_anything.embed_file("test_files/TUe_SOP_AI_2.pdf", embeder= "Bert")

# embeddings = np.array([data.embedding for data in data])


# print(embeddings)
# print("Time taken: ", end-start)

start = time.time()
data:list[EmbedData] = embed_anything.embed_directory("test_files", embeder= "Clip")

Expand Down
Loading