Providers API
culicidaelab.providers
Data provider implementations for accessing datasets and models.
This package contains classes that implement the BaseProvider
interface
to interact with various data sources like Hugging Face, Kaggle, etc.
Each provider module offers specific logic for downloading datasets
and model weights.
Available Classes
- HuggingFaceProvider: A provider for interacting with the Hugging Face Hub.
__all__ = ['HuggingFaceProvider']
module-attribute
HuggingFaceProvider
Provider for downloading and managing HuggingFace datasets and models.
This class interfaces with the Hugging Face Hub to fetch dataset metadata, download full datasets or specific splits, and download model weights. It uses the core settings object for path resolution and API key access.
Attributes:
Name | Type | Description |
---|---|---|
provider_name |
str
|
The name of the provider, "huggingface". |
settings |
Settings
|
The main Settings object for the library. |
dataset_url |
str
|
The base URL for fetching Hugging Face dataset metadata. |
api_key |
str | None
|
The Hugging Face API key, if provided. |
Source code in culicidaelab/providers/huggingface_provider.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
provider_name = 'huggingface'
instance-attribute
settings = settings
instance-attribute
dataset_url = dataset_url
instance-attribute
api_key: str | None = kwargs.get('api_key') or self.settings.get_api_key(self.provider_name)
instance-attribute
__init__(settings: Settings, dataset_url: str, **kwargs: Any) -> None
Initializes the HuggingFace provider.
This constructor is called by the ProviderService
, which injects the
global settings
object and unpacks the specific provider's configuration
(e.g., dataset_url
) as keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings
|
Settings
|
The main Settings object for the library. |
required |
dataset_url
|
str
|
The base URL for fetching Hugging Face dataset metadata. |
required |
**kwargs
|
Any
|
Catches other config parameters (e.g., |
{}
|
Source code in culicidaelab/providers/huggingface_provider.py
download_dataset(dataset_name: str, save_dir: str | None = None, split: str | None = None, *args: Any, **kwargs: Any) -> Path
Downloads a dataset from HuggingFace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
Name of the dataset to download (e.g., "segmentation"). |
required |
save_dir
|
str | None
|
Directory to save the dataset. Defaults to None, using the path from settings. |
None
|
split
|
str | None
|
Dataset split to download (e.g., "train"). Defaults to None. |
None
|
*args
|
Any
|
Additional positional arguments to pass to |
()
|
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
The path to the downloaded dataset. |
Raises:
Type | Description |
---|---|
ValueError
|
If the configuration is missing the |
RuntimeError
|
If the download fails. |
Source code in culicidaelab/providers/huggingface_provider.py
download_model_weights(model_type: str, *args: Any, **kwargs: Any) -> Path
Downloads and caches model weights from the HuggingFace Hub.
Checks if the weights exist locally. If not, it downloads them from the repository specified in the configuration and saves them to the appropriate directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_type
|
str
|
The type of model ('detector', 'segmenter', or 'classifier'). |
required |
*args
|
Any
|
Additional positional arguments (unused). |
()
|
**kwargs
|
Any
|
Additional keyword arguments (unused). |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
The path to the model weights file. |
Raises:
Type | Description |
---|---|
ValueError
|
If the model type is not found in config or if |
RuntimeError
|
If the download fails for any reason. |
NotADirectoryError
|
If the destination directory could not be created. |
Source code in culicidaelab/providers/huggingface_provider.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
get_dataset_metadata(dataset_name: str) -> dict[str, Any]
Gets metadata for a specific dataset from HuggingFace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
str
|
The name of the dataset to get metadata for. |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: The dataset metadata as a dictionary. |
Raises:
Type | Description |
---|---|
RequestException
|
If the HTTP request fails. |
Source code in culicidaelab/providers/huggingface_provider.py
get_provider_name() -> str
Returns the provider's name.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the provider, "huggingface". |
load_dataset(dataset_path: str | Path, split: str | None = None, **kwargs: Any) -> Any
Loads a dataset from disk.
This method attempts to load a dataset from the specified path. If a split
name is provided and a corresponding subdirectory exists, it will load
the split from that subdirectory. Otherwise, it loads the entire dataset
from the base path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_path
|
str | Path
|
The local path to the dataset,
typically returned by |
required |
split
|
str | None
|
The specific split to load (e.g., "train", "validation", "test"). If a subdirectory with this name exists, it will be loaded. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The loaded dataset, typically a |
Source code in culicidaelab/providers/huggingface_provider.py
selection:
members: true