Skip to content
Merged

Dev #192

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
28 changes: 8 additions & 20 deletions python/python/embed_anything/_embed_anything.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class ColpaliModel:
revision: The revision of the model.
"""

@staticmethod
def from_pretrained(model_id: str, revision: str | None = None) -> ColpaliModel:
"""
Loads a pre-trained Colpali model from the Hugging Face model hub.
Expand All @@ -347,6 +348,7 @@ class ColpaliModel:
A ColpaliModel object.
"""

@staticmethod
def from_pretrained_onnx(
model_id: str, revision: str | None = None
) -> ColpaliModel:
Expand Down Expand Up @@ -400,8 +402,8 @@ class ColbertModel:
Initializes the ColbertModel object.
"""

@staticmethod
def from_pretrained_onnx(
self,
hf_model_id: str | None = None,
revision: str | None = None,
path_in_repo: str | None = None,
Expand Down Expand Up @@ -437,6 +439,7 @@ class Reranker:
Initializes the Reranker object.
"""

@staticmethod
def from_pretrained(
model_id: str, revision: str | None = None, dtype: Dtype | None = None, path_in_repo: str | None = None
) -> Reranker:
Expand Down Expand Up @@ -590,6 +593,7 @@ class EmbeddingModel:
Represents an embedding model.
"""

@staticmethod
def from_pretrained_hf(
model_id: str,
revision: str | None = None,
Expand Down Expand Up @@ -617,6 +621,7 @@ class EmbeddingModel:

"""

@staticmethod
def from_pretrained_cloud(
model: WhichModel, model_id: str, api_key: str | None = None
) -> EmbeddingModel:
Expand Down Expand Up @@ -657,6 +662,7 @@ class EmbeddingModel:
```
"""

@staticmethod
def from_pretrained_onnx(
model: WhichModel,
model_name: Optional[ONNXModel] | None = None,
Expand Down Expand Up @@ -830,23 +836,6 @@ class EmbeddingModel:
A list of EmbedData objects.
"""

def embed_webpage(
self,
url: str,
config: TextEmbedConfig | None = None,
adapter: Adapter | None = None,
) -> list[EmbedData]:
"""
Embeds the given webpage and returns a list of EmbedData objects.

Args:
url: The URL of the webpage to embed.
config: The configuration for the embedding.
adapter: The adapter for the embedding.

Returns:
A list of EmbedData objects.
"""

class AudioDecoderModel:
"""
Expand Down Expand Up @@ -875,6 +864,7 @@ class AudioDecoderModel:
model_type: str
quantized: bool

@staticmethod
def from_pretrained_hf(
model_id: str | None = None,
revision: str | None = None,
Expand Down Expand Up @@ -1005,5 +995,3 @@ class ONNXModel(Enum):
SPLADEPPENV1 = "SPLADEPPENV1"

SPLADEPPENV2 = "SPLADEPPENV2"

ModernBERTBase = "ModernBERTBase"
2 changes: 1 addition & 1 deletion rust/src/embeddings/local/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl ClipEmbedder {
) -> anyhow::Result<Tokenizer> {
let tokenizer = match tokenizer {
None => {
let api = hf_hub::api::sync::Api::new()?;
let api = hf_hub::api::sync::ApiBuilder::from_env().build()?;
let api = match revision {
Some(rev) => api.repo(hf_hub::Repo::with_revision(
model_id,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/embeddings/local/colbert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate accelerate_src;
use std::{ops::Mul, sync::RwLock};

use anyhow::{Error as E, Result};
use hf_hub::{api::sync::Api, Repo};
use hf_hub::{api::sync::ApiBuilder, Repo};
use ndarray::{Array2, Axis};
use ort::{
execution_providers::{CUDAExecutionProvider, CoreMLExecutionProvider, ExecutionProvider},
Expand Down Expand Up @@ -52,7 +52,7 @@ impl OrtColbertEmbedder {
};

let (_, tokenizer_filename, weights_filename, tokenizer_config_filename, data_filename) = {
let api = Api::new().unwrap();
let api = ApiBuilder::from_env().build().unwrap();
let api = match revision {
Some(rev) => api.repo(Repo::with_revision(
hf_model_id.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion rust/src/embeddings/local/colpali.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct ColPaliEmbedder {

impl ColPaliEmbedder {
pub fn new(model_id: &str, revision: Option<&str>) -> Result<Self, anyhow::Error> {
let api = hf_hub::api::sync::Api::new()?;
let api = hf_hub::api::sync::ApiBuilder::from_env().build()?;
let repo: hf_hub::api::sync::ApiRepo = match revision {
Some(rev) => api.repo(hf_hub::Repo::with_revision(
model_id.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion rust/src/embeddings/local/colpali_ort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl OrtColPaliEmbedder {
revision: Option<&str>,
path_in_repo: Option<&str>,
) -> Result<Self, E> {
let api = hf_hub::api::sync::Api::new()?;
let api = hf_hub::api::sync::ApiBuilder::from_env().build()?;
let repo: hf_hub::api::sync::ApiRepo = match revision {
Some(rev) => api.repo(hf_hub::Repo::with_revision(
model_id.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion rust/src/embeddings/local/colsmol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ColSmolEmbedder {

impl ColSmolEmbedder {
pub fn new(model_id: &str, revision: Option<&str>) -> Result<Self, anyhow::Error> {
let api = hf_hub::api::sync::Api::new()?;
let api = hf_hub::api::sync::ApiBuilder::from_env().build()?;
let repo: hf_hub::api::sync::ApiRepo = match revision {
Some(rev) => api.repo(hf_hub::Repo::with_revision(
model_id.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions rust/src/embeddings/local/ort_bert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::embeddings::utils::{get_type_ids_ndarray, tokenize_batch_ndarray};

use crate::Dtype;
use anyhow::Error as E;
use hf_hub::api::sync::Api;
use hf_hub::api::sync::ApiBuilder;
use hf_hub::Repo;
use ndarray::prelude::*;
use ort::execution_providers::{CUDAExecutionProvider, CoreMLExecutionProvider, ExecutionProvider};
Expand Down Expand Up @@ -62,7 +62,7 @@ impl OrtBertEmbedder {
};

let (_, tokenizer_filename, weights_filename, tokenizer_config_filename) = {
let api = Api::new().unwrap();
let api = ApiBuilder::from_env().build().unwrap();
let api = match revision {
Some(rev) => api.repo(Repo::with_revision(
hf_model_id.to_string(),
Expand Down Expand Up @@ -418,7 +418,7 @@ impl OrtSparseBertEmbedder {
};

let (_, tokenizer_filename, weights_filename, tokenizer_config_filename) = {
let api = Api::new().unwrap();
let api = ApiBuilder::from_env().build().unwrap();
let api = match revision {
Some(rev) => api.repo(Repo::with_revision(
hf_model_id.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion rust/src/embeddings/local/ort_colsmol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl OrtColSmolEmbedder {
revision: Option<&str>,
path_in_repo: Option<&str>,
) -> Result<Self, E> {
let api = hf_hub::api::sync::Api::new()?;
let api = hf_hub::api::sync::ApiBuilder::from_env().build()?;
let repo: hf_hub::api::sync::ApiRepo = match revision {
Some(rev) => api.repo(hf_hub::Repo::with_revision(
model_id.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions rust/src/embeddings/local/ort_jina.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::embeddings::embed::EmbeddingResult;
use crate::embeddings::utils::tokenize_batch_ndarray;
use crate::Dtype;
use anyhow::Error as E;
use hf_hub::api::sync::Api;
use hf_hub::api::sync::ApiBuilder;
use hf_hub::Repo;
use ndarray::prelude::*;
use std::sync::RwLock;
Expand Down Expand Up @@ -63,7 +63,7 @@ impl OrtJinaEmbedder {
};

let (_, tokenizer_filename, weights_filename, tokenizer_config_filename) = {
let api = Api::new().unwrap();
let api = ApiBuilder::from_env().build().unwrap();
let api = match revision {
Some(rev) => api.repo(Repo::with_revision(
hf_model_id.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions rust/src/file_processor/audio/audio_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
use anyhow::{Error as E, Result};
use candle_core::{Device, IndexOp, Tensor};
use candle_nn::{ops::softmax, VarBuilder};
use hf_hub::{api::sync::Api, Repo, RepoType};
use hf_hub::{api::sync::ApiBuilder, Repo, RepoType};
use rand::{
distr::{weighted::WeightedIndex, Distribution},
SeedableRng,
Expand Down Expand Up @@ -458,7 +458,7 @@ pub fn build_model(
(None, None) => (default_model, default_revision),
};

let api = Api::new()?;
let api = ApiBuilder::from_env().build()?;
let repo = api.repo(Repo::with_revision(
model_id.to_string(),
RepoType::Model,
Expand Down
8 changes: 4 additions & 4 deletions rust/src/models/idefics3/array_processing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use anyhow::{Error, Ok};
use hf_hub::{api::sync::Api, Repo, RepoType};
use hf_hub::{api::sync::ApiBuilder, Repo, RepoType};
use image::{imageops::FilterType, DynamicImage, GenericImageView, RgbImage};
use ndarray::{s, Array2};
use regex::Regex;
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Idefics3ImageProcessor {
}

pub fn from_pretrained(model_id: &str) -> Result<Self, anyhow::Error> {
let api = Api::new()?;
let api = ApiBuilder::from_env().build()?;
let repo = api.repo(Repo::new(model_id.to_string(), RepoType::Model));
let config_file = repo.get("preprocessor_config.json").unwrap();
let processor: Idefics3ImageProcessor =
Expand Down Expand Up @@ -692,7 +692,7 @@ fn normalize(
#[cfg(test)]
mod tests {
use super::*;
use hf_hub::api::sync::Api;
use hf_hub::api::sync::ApiBuilder;
use hf_hub::{Repo, RepoType};
use image::RgbImage;

Expand All @@ -701,7 +701,7 @@ mod tests {
let image = image::open("/home/akshay/projects/EmbedAnything/test.jpg").unwrap();
let image_array = image.to_rgb8().into_raw();

let api = Api::new().unwrap();
let api = ApiBuilder::from_env().build().unwrap();
let repo = api.repo(Repo::new(
"onnx-community/colSmol-256M-ONNX".to_string(),
RepoType::Model,
Expand Down
6 changes: 3 additions & 3 deletions rust/src/models/idefics3/tensor_processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use candle_core::{DType, Device, Tensor};
use hf_hub::{api::sync::Api, Repo, RepoType};
use hf_hub::{api::sync::ApiBuilder, Repo, RepoType};
use image::{imageops::FilterType, DynamicImage, GenericImageView, RgbImage};
use serde::Deserialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Idefics3ImageProcessor {
}

pub fn from_pretrained(model_id: &str) -> Result<Self, anyhow::Error> {
let api = Api::new()?;
let api = ApiBuilder::from_env().build()?;
let repo = api.repo(Repo::new(model_id.to_string(), RepoType::Model));
let config_file = repo.get("preprocessor_config.json")?;
let processor: Idefics3ImageProcessor =
Expand All @@ -525,7 +525,7 @@ pub struct Idefics3Processor {
impl Idefics3Processor {
pub fn from_pretrained(model_id: &str) -> anyhow::Result<Self> {
let image_processor = Idefics3ImageProcessor::from_pretrained(model_id)?;
let api = Api::new()?;
let api = ApiBuilder::from_env().build()?;
let repo = api.repo(Repo::new(model_id.to_string(), RepoType::Model));

let processor_config_file = repo.get("processor_config.json")?;
Expand Down
4 changes: 2 additions & 2 deletions rust/src/reranker/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::RwLock;

use anyhow::{Error as E, Result};
use candle_core::{Device, Tensor};
use hf_hub::{api::sync::Api, Repo};
use hf_hub::{api::sync::ApiBuilder, Repo};
use ndarray::Array2;
use ort::{
execution_providers::{CUDAExecutionProvider, CoreMLExecutionProvider, ExecutionProvider},
Expand Down Expand Up @@ -41,7 +41,7 @@ impl Reranker {
path_in_repo: Option<&str>,
) -> Result<Self, E> {
let (config_filename, tokenizer_filename, weights_filename, tokenizer_config_filename) = {
let api = Api::new().unwrap();
let api = ApiBuilder::from_env().build().unwrap();
let api = match revision {
Some(rev) => api.repo(Repo::with_revision(
model_id.to_string(),
Expand Down
Loading