sinapsis-huggingface 0.2.11__tar.gz → 0.2.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/PKG-INFO +14 -1
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/README.md +12 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface.egg-info/PKG-INFO +14 -1
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface.egg-info/SOURCES.txt +5 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface.egg-info/requires.txt +1 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface.egg-info/top_level.txt +1 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/templates/base_diffusers.py +41 -9
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/templates/image_to_image_diffusers.py +12 -11
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/templates/image_to_video_gen_xl_diffusers.py +10 -5
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/templates/inpainting_diffusers.py +7 -3
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/templates/text_to_image_diffusers.py +1 -1
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/templates/grounding_dino.py +32 -12
- sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/helpers/tags.py +7 -0
- sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/templates/__init__.py +19 -0
- sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/templates/huggingface_downloader.py +71 -0
- sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/image_to_text_transformers.py +1 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/pali_gemma/pali_gemma_base.py +1 -1
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/speech_to_text_transformers.py +1 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/summarization_transformers.py +1 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/text_to_speech_transformers.py +1 -0
- sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/thirdparty/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/pyproject.toml +3 -1
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/LICENSE +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface.egg-info/dependency_links.txt +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/helpers/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/helpers/tags.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_diffusers/src/sinapsis_huggingface_diffusers/templates/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_embeddings/src/sinapsis_huggingface_embeddings/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_embeddings/src/sinapsis_huggingface_embeddings/helpers/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_embeddings/src/sinapsis_huggingface_embeddings/helpers/tags.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_embeddings/src/sinapsis_huggingface_embeddings/templates/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_embeddings/src/sinapsis_huggingface_embeddings/templates/hugging_face_embedding_extractor.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_embeddings/src/sinapsis_huggingface_embeddings/templates/speaker_embedding_from_audio.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/helpers/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/helpers/grounding_dino_keys.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/helpers/tags.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/templates/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/templates/grounding_dino_classification.py +0 -0
- {sinapsis_huggingface-0.2.11/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers → sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub}/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/thirdparty → sinapsis_huggingface-0.2.13/packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/helpers}/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/helpers/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/helpers/tags.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/helpers/text_to_sentences.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/__init__.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/base_transformers.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/pali_gemma/pali_gemma_detection.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/pali_gemma/pali_gemma_inference.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/templates/translation_transformers.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/thirdparty/helpers.py +0 -0
- {sinapsis_huggingface-0.2.11 → sinapsis_huggingface-0.2.13}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-huggingface
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.13
|
|
4
4
|
Summary: Package for HuggingFace-based templates
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -23,6 +23,7 @@ Requires-Dist: sinapsis-huggingface-diffusers[all]; extra == "all"
|
|
|
23
23
|
Requires-Dist: sinapsis-huggingface-embeddings; extra == "all"
|
|
24
24
|
Requires-Dist: sinapsis-huggingface-grounding-dino; extra == "all"
|
|
25
25
|
Requires-Dist: sinapsis-huggingface-transformers; extra == "all"
|
|
26
|
+
Requires-Dist: sinapsis-huggingface-hub[all]; extra == "all"
|
|
26
27
|
Requires-Dist: sinapsis-huggingface[gradio-app,sinapsis-data-writers]; extra == "all"
|
|
27
28
|
Provides-Extra: sinapsis-data-writers
|
|
28
29
|
Requires-Dist: sinapsis-data-writers>=0.1.0; extra == "sinapsis-data-writers"
|
|
@@ -60,6 +61,7 @@ This repo consists of different packages to handle huggingface tools for differe
|
|
|
60
61
|
* <code>sinapsis-huggingface-embeddings</code>
|
|
61
62
|
* <code>sinapsis-huggingface-grounding-dino</code>
|
|
62
63
|
* <code>sinapsis-huggingface-transformers</code>
|
|
64
|
+
* <code>sinapsis-huggingface-hub</code>
|
|
63
65
|
|
|
64
66
|
Install using your package manager of choice. We encourage the use of <code>uv</code>
|
|
65
67
|
|
|
@@ -151,6 +153,17 @@ For more details and specific templates, see the [README.md](https://github.com/
|
|
|
151
153
|
|
|
152
154
|
</details>
|
|
153
155
|
|
|
156
|
+
<details>
|
|
157
|
+
<summary id="uv"><strong><span style="font-size: 1.4em;">Sinapsis Hugging Face Hub</span></strong></summary>
|
|
158
|
+
|
|
159
|
+
This sinapsis package offers templates to manage **datasets**, **models** and **spaces** with the Hugging Face Hub library. Currently it offers:
|
|
160
|
+
|
|
161
|
+
- **HuggingFaceDownloader**: Downloads a repository snapshot from the Hugging Face Hub.
|
|
162
|
+
|
|
163
|
+
For more details and specific templates, see the [README.md](https://github.com/Sinapsis-AI/sinapsis-huggingface/blob/main/packages/sinapsis_huggingface_hub/README.md).
|
|
164
|
+
|
|
165
|
+
</details>
|
|
166
|
+
|
|
154
167
|
For more details, see the [official documentation](https://docs.sinapsis.tech/docs)
|
|
155
168
|
|
|
156
169
|
<h2 id="webapps">🌐 Webapps</h2>
|
|
@@ -30,6 +30,7 @@ This repo consists of different packages to handle huggingface tools for differe
|
|
|
30
30
|
* <code>sinapsis-huggingface-embeddings</code>
|
|
31
31
|
* <code>sinapsis-huggingface-grounding-dino</code>
|
|
32
32
|
* <code>sinapsis-huggingface-transformers</code>
|
|
33
|
+
* <code>sinapsis-huggingface-hub</code>
|
|
33
34
|
|
|
34
35
|
Install using your package manager of choice. We encourage the use of <code>uv</code>
|
|
35
36
|
|
|
@@ -121,6 +122,17 @@ For more details and specific templates, see the [README.md](https://github.com/
|
|
|
121
122
|
|
|
122
123
|
</details>
|
|
123
124
|
|
|
125
|
+
<details>
|
|
126
|
+
<summary id="uv"><strong><span style="font-size: 1.4em;">Sinapsis Hugging Face Hub</span></strong></summary>
|
|
127
|
+
|
|
128
|
+
This sinapsis package offers templates to manage **datasets**, **models** and **spaces** with the Hugging Face Hub library. Currently it offers:
|
|
129
|
+
|
|
130
|
+
- **HuggingFaceDownloader**: Downloads a repository snapshot from the Hugging Face Hub.
|
|
131
|
+
|
|
132
|
+
For more details and specific templates, see the [README.md](https://github.com/Sinapsis-AI/sinapsis-huggingface/blob/main/packages/sinapsis_huggingface_hub/README.md).
|
|
133
|
+
|
|
134
|
+
</details>
|
|
135
|
+
|
|
124
136
|
For more details, see the [official documentation](https://docs.sinapsis.tech/docs)
|
|
125
137
|
|
|
126
138
|
<h2 id="webapps">🌐 Webapps</h2>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-huggingface
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.13
|
|
4
4
|
Summary: Package for HuggingFace-based templates
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -23,6 +23,7 @@ Requires-Dist: sinapsis-huggingface-diffusers[all]; extra == "all"
|
|
|
23
23
|
Requires-Dist: sinapsis-huggingface-embeddings; extra == "all"
|
|
24
24
|
Requires-Dist: sinapsis-huggingface-grounding-dino; extra == "all"
|
|
25
25
|
Requires-Dist: sinapsis-huggingface-transformers; extra == "all"
|
|
26
|
+
Requires-Dist: sinapsis-huggingface-hub[all]; extra == "all"
|
|
26
27
|
Requires-Dist: sinapsis-huggingface[gradio-app,sinapsis-data-writers]; extra == "all"
|
|
27
28
|
Provides-Extra: sinapsis-data-writers
|
|
28
29
|
Requires-Dist: sinapsis-data-writers>=0.1.0; extra == "sinapsis-data-writers"
|
|
@@ -60,6 +61,7 @@ This repo consists of different packages to handle huggingface tools for differe
|
|
|
60
61
|
* <code>sinapsis-huggingface-embeddings</code>
|
|
61
62
|
* <code>sinapsis-huggingface-grounding-dino</code>
|
|
62
63
|
* <code>sinapsis-huggingface-transformers</code>
|
|
64
|
+
* <code>sinapsis-huggingface-hub</code>
|
|
63
65
|
|
|
64
66
|
Install using your package manager of choice. We encourage the use of <code>uv</code>
|
|
65
67
|
|
|
@@ -151,6 +153,17 @@ For more details and specific templates, see the [README.md](https://github.com/
|
|
|
151
153
|
|
|
152
154
|
</details>
|
|
153
155
|
|
|
156
|
+
<details>
|
|
157
|
+
<summary id="uv"><strong><span style="font-size: 1.4em;">Sinapsis Hugging Face Hub</span></strong></summary>
|
|
158
|
+
|
|
159
|
+
This sinapsis package offers templates to manage **datasets**, **models** and **spaces** with the Hugging Face Hub library. Currently it offers:
|
|
160
|
+
|
|
161
|
+
- **HuggingFaceDownloader**: Downloads a repository snapshot from the Hugging Face Hub.
|
|
162
|
+
|
|
163
|
+
For more details and specific templates, see the [README.md](https://github.com/Sinapsis-AI/sinapsis-huggingface/blob/main/packages/sinapsis_huggingface_hub/README.md).
|
|
164
|
+
|
|
165
|
+
</details>
|
|
166
|
+
|
|
154
167
|
For more details, see the [official documentation](https://docs.sinapsis.tech/docs)
|
|
155
168
|
|
|
156
169
|
<h2 id="webapps">🌐 Webapps</h2>
|
|
@@ -28,6 +28,11 @@ packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_
|
|
|
28
28
|
packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/templates/__init__.py
|
|
29
29
|
packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/templates/grounding_dino.py
|
|
30
30
|
packages/sinapsis_huggingface_grounding_dino/src/sinapsis_huggingface_grounding_dino/templates/grounding_dino_classification.py
|
|
31
|
+
packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/__init__.py
|
|
32
|
+
packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/helpers/__init__.py
|
|
33
|
+
packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/helpers/tags.py
|
|
34
|
+
packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/templates/__init__.py
|
|
35
|
+
packages/sinapsis_huggingface_hub/src/sinapsis_huggingface_hub/templates/huggingface_downloader.py
|
|
31
36
|
packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/__init__.py
|
|
32
37
|
packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/helpers/__init__.py
|
|
33
38
|
packages/sinapsis_huggingface_transformers/src/sinapsis_huggingface_transformers/helpers/tags.py
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
|
+
import gc
|
|
3
4
|
from abc import ABC, abstractmethod
|
|
4
5
|
from typing import Literal
|
|
5
6
|
|
|
@@ -70,7 +71,7 @@ class BaseDiffusersAttributes(TemplateAttributes):
|
|
|
70
71
|
Defaults to False.
|
|
71
72
|
"""
|
|
72
73
|
|
|
73
|
-
model_path:
|
|
74
|
+
model_path: Literal["stable-diffusion-v1-5/stable-diffusion-v1-5", "stabilityai/stable-diffusion-2-1", "CompVis/stable-diffusion-v1-4", "Qwen/Qwen-Image-Edit"] = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
|
74
75
|
model_cache_dir: str = str(SINAPSIS_CACHE_DIR)
|
|
75
76
|
device: Literal["cuda", "cpu"]
|
|
76
77
|
torch_dtype: Literal["float16", "float32"] = "float16"
|
|
@@ -107,7 +108,14 @@ class BaseDiffusers(Template, ABC):
|
|
|
107
108
|
|
|
108
109
|
def __init__(self, attributes: TemplateAttributeType) -> None:
|
|
109
110
|
super().__init__(attributes)
|
|
111
|
+
self.initialize()
|
|
110
112
|
|
|
113
|
+
def initialize(self) -> None:
|
|
114
|
+
"""Initializes the template's common state for creation or reset.
|
|
115
|
+
|
|
116
|
+
This method is called by both `__init__` and `reset_state` to ensure
|
|
117
|
+
a consistent state. Can be overriden by subclasses for specific behaviour.
|
|
118
|
+
"""
|
|
111
119
|
self.pipeline = self._make_pipeline()
|
|
112
120
|
self.pipeline.set_progress_bar_config(disable=True)
|
|
113
121
|
self.num_images_per_prompt = self.attributes.generation_params.num_images_per_prompt
|
|
@@ -155,7 +163,7 @@ class BaseDiffusers(Template, ABC):
|
|
|
155
163
|
pipeline_class = self._pipeline_class()
|
|
156
164
|
return pipeline_class.from_pretrained(
|
|
157
165
|
self.attributes.model_path,
|
|
158
|
-
|
|
166
|
+
dtype=self.TORCH_DTYPE.get(self.attributes.torch_dtype),
|
|
159
167
|
cache_dir=self.attributes.model_cache_dir,
|
|
160
168
|
).to(self.attributes.device)
|
|
161
169
|
|
|
@@ -199,8 +207,10 @@ class BaseDiffusers(Template, ABC):
|
|
|
199
207
|
output_type="np",
|
|
200
208
|
)
|
|
201
209
|
generated_images = output.images if output_attribute == "images" else output.frames[0]
|
|
210
|
+
images_as_uint8 = [(image * 255).clip(0, 255).astype(np.uint8) for image in generated_images]
|
|
211
|
+
del output
|
|
202
212
|
|
|
203
|
-
return
|
|
213
|
+
return images_as_uint8
|
|
204
214
|
|
|
205
215
|
def _update_images_in_container(self, container: DataContainer, new_packets: list[ImagePacket]) -> None:
|
|
206
216
|
"""Updates the container with new image packets based on the `overwrite_images` attribute.
|
|
@@ -218,17 +228,39 @@ class BaseDiffusers(Template, ABC):
|
|
|
218
228
|
else:
|
|
219
229
|
container.images.extend(new_packets)
|
|
220
230
|
|
|
221
|
-
|
|
231
|
+
@staticmethod
|
|
232
|
+
def clear_memory() -> None:
|
|
222
233
|
"""Clears memory to free up resources.
|
|
223
234
|
|
|
224
235
|
This method performs garbage collection and clears GPU memory (if applicable) to prevent memory leaks
|
|
225
236
|
and ensure efficient resource usage.
|
|
226
237
|
"""
|
|
227
|
-
|
|
228
|
-
if
|
|
238
|
+
gc.collect()
|
|
239
|
+
if torch.cuda.is_available():
|
|
229
240
|
torch.cuda.empty_cache()
|
|
230
|
-
torch.cuda.ipc_collect()
|
|
231
241
|
|
|
232
242
|
def reset_state(self, template_name: str | None = None) -> None:
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
"""Releases the pipeline and processor from memory and re-instantiates the template.
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
template_name (str | None, optional): The name of the template instance being reset. Defaults to None.
|
|
247
|
+
"""
|
|
248
|
+
_ = template_name
|
|
249
|
+
|
|
250
|
+
if hasattr(self, "pipeline") and self.pipeline is not None:
|
|
251
|
+
components = self.pipeline.components
|
|
252
|
+
for component in components.values():
|
|
253
|
+
if isinstance(component, torch.nn.Module):
|
|
254
|
+
component.to("cpu")
|
|
255
|
+
|
|
256
|
+
del self.pipeline
|
|
257
|
+
|
|
258
|
+
if hasattr(self, "processor"):
|
|
259
|
+
del self.processor
|
|
260
|
+
|
|
261
|
+
if hasattr(self, "generator"):
|
|
262
|
+
del self.generator
|
|
263
|
+
|
|
264
|
+
self.clear_memory()
|
|
265
|
+
self.initialize()
|
|
266
|
+
self.logger.info(f"Reset template instance `{self.instance_name}`")
|
|
@@ -8,7 +8,6 @@ import numpy as np
|
|
|
8
8
|
from diffusers import AutoPipelineForImage2Image
|
|
9
9
|
from PIL import Image
|
|
10
10
|
from sinapsis_core.data_containers.data_packet import DataContainer, ImagePacket
|
|
11
|
-
from sinapsis_core.template_base.base_models import TemplateAttributeType
|
|
12
11
|
|
|
13
12
|
from sinapsis_huggingface_diffusers.helpers.tags import Tags
|
|
14
13
|
from sinapsis_huggingface_diffusers.templates.base_diffusers import BaseDiffusers
|
|
@@ -52,9 +51,13 @@ class ImageToImageDiffusers(BaseDiffusers):
|
|
|
52
51
|
|
|
53
52
|
UIProperties = ImageToImageDiffusersUIProperties
|
|
54
53
|
|
|
55
|
-
def
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
def initialize(self) -> None:
|
|
55
|
+
"""Initializes the template's common state for creation or reset.
|
|
56
|
+
|
|
57
|
+
This method is called by both `__init__` and `reset_state` to ensure
|
|
58
|
+
a consistent state. Can be overriden by subclasses for specific behaviour.
|
|
59
|
+
"""
|
|
60
|
+
super().initialize()
|
|
58
61
|
self.output_attribute: Literal["images", "frames"] = "images"
|
|
59
62
|
self.num_duplicates = self.num_images_per_prompt
|
|
60
63
|
|
|
@@ -67,7 +70,8 @@ class ImageToImageDiffusers(BaseDiffusers):
|
|
|
67
70
|
"""
|
|
68
71
|
return AutoPipelineForImage2Image
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
@staticmethod
|
|
74
|
+
def _convert_image_format(image_packet: ImagePacket) -> Image.Image:
|
|
71
75
|
"""Converts the input image into the appropriate format for the pipeline.
|
|
72
76
|
|
|
73
77
|
The format depends on the `requires_pil` attribute:
|
|
@@ -78,12 +82,9 @@ class ImageToImageDiffusers(BaseDiffusers):
|
|
|
78
82
|
image_packet (ImagePacket): The input image packet.
|
|
79
83
|
|
|
80
84
|
Returns:
|
|
81
|
-
|
|
82
|
-
PIL Image.
|
|
85
|
+
Image.Image: The converted image as a PIL Image.
|
|
83
86
|
"""
|
|
84
|
-
|
|
85
|
-
return Image.fromarray(image_packet.content)
|
|
86
|
-
return image_packet.content / 255.0
|
|
87
|
+
return Image.fromarray(image_packet.content)
|
|
87
88
|
|
|
88
89
|
def preprocess_inputs(self, image_packet: ImagePacket) -> dict[str, np.ndarray | list[np.ndarray]]:
|
|
89
90
|
"""Prepares the input image for the image-to-image pipeline.
|
|
@@ -157,6 +158,6 @@ class ImageToImageDiffusers(BaseDiffusers):
|
|
|
157
158
|
new_packets = [ImagePacket(content=image) for image in all_generated_images]
|
|
158
159
|
processed_packets, _ = self.post_processing_packets(new_packets, old_packets)
|
|
159
160
|
self._update_images_in_container(container, processed_packets)
|
|
160
|
-
self.
|
|
161
|
+
self.clear_memory()
|
|
161
162
|
|
|
162
163
|
return container
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
2
4
|
from diffusers import I2VGenXLPipeline
|
|
3
5
|
from pydantic import Field
|
|
4
|
-
from sinapsis_core.template_base.base_models import TemplateAttributeType
|
|
5
6
|
|
|
6
7
|
from sinapsis_huggingface_diffusers.helpers.tags import Tags
|
|
7
8
|
from sinapsis_huggingface_diffusers.templates.base_diffusers import BaseDiffusersAttributes, BaseGenerationParams
|
|
@@ -72,11 +73,15 @@ class ImageToVideoGenXLDiffusers(ImageToImageDiffusers):
|
|
|
72
73
|
AttributesBaseModel = ImageToVideoGenXLDiffusersAttributes
|
|
73
74
|
UIProperties = ImageToVideoGenXLDiffusersUIProperties
|
|
74
75
|
|
|
75
|
-
def
|
|
76
|
-
|
|
76
|
+
def initialize(self) -> None:
|
|
77
|
+
"""Initializes the template's common state for creation or reset.
|
|
78
|
+
|
|
79
|
+
This method is called by both `__init__` and `reset_state` to ensure
|
|
80
|
+
a consistent state. Can be overriden by subclasses for specific behaviour.
|
|
81
|
+
"""
|
|
82
|
+
super().initialize()
|
|
83
|
+
self.output_attribute: Literal["images", "frames"] = "frames"
|
|
77
84
|
self.num_duplicates = self.attributes.generation_params.num_frames
|
|
78
|
-
self.requires_pil = True
|
|
79
|
-
self.output_attribute = "frames"
|
|
80
85
|
|
|
81
86
|
@staticmethod
|
|
82
87
|
def _pipeline_class() -> I2VGenXLPipeline:
|
|
@@ -7,7 +7,6 @@ import cv2
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from diffusers import AutoPipelineForInpainting
|
|
9
9
|
from sinapsis_core.data_containers.data_packet import ImageAnnotations, ImagePacket
|
|
10
|
-
from sinapsis_core.template_base.base_models import TemplateAttributeType
|
|
11
10
|
|
|
12
11
|
from sinapsis_huggingface_diffusers.helpers.tags import Tags
|
|
13
12
|
from sinapsis_huggingface_diffusers.templates.base_diffusers import (
|
|
@@ -75,8 +74,13 @@ class InpaintingDiffusers(ImageToImageDiffusers):
|
|
|
75
74
|
UIProperties = InpaintingDiffusersUIProperties
|
|
76
75
|
AttributesBaseModel = InpaintingDiffusersAttributes
|
|
77
76
|
|
|
78
|
-
def
|
|
79
|
-
|
|
77
|
+
def initialize(self) -> None:
|
|
78
|
+
"""Initializes the template's common state for creation or reset.
|
|
79
|
+
|
|
80
|
+
This method is called by both `__init__` and `reset_state` to ensure
|
|
81
|
+
a consistent state. Can be overriden by subclasses for specific behaviour.
|
|
82
|
+
"""
|
|
83
|
+
super().initialize()
|
|
80
84
|
if self.attributes.preserve_outside_content and self.attributes.dilation_radius is None:
|
|
81
85
|
raise ValueError("Need to specify a dilation_radius if preserve_outside_content=True")
|
|
82
86
|
|
|
@@ -80,6 +80,6 @@ class TextToImageDiffusers(BaseDiffusers):
|
|
|
80
80
|
image_packets = [ImagePacket(content=image) for image in generated_images]
|
|
81
81
|
self._set_packet_sources(image_packets)
|
|
82
82
|
self._update_images_in_container(container, image_packets)
|
|
83
|
-
self.
|
|
83
|
+
self.clear_memory()
|
|
84
84
|
|
|
85
85
|
return container
|
|
@@ -42,7 +42,7 @@ class GroundingBaseAttributes(TemplateAttributes):
|
|
|
42
42
|
device (Literal["cuda", "cpu"]): Device to be used for inference.
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
model_path:
|
|
45
|
+
model_path: Literal["IDEA-Research/grounding-dino-base"] = "IDEA-Research/grounding-dino-base"
|
|
46
46
|
model_cache_dir: str = str(SINAPSIS_CACHE_DIR)
|
|
47
47
|
inference_mode: Literal["object_detection", "zero_shot"]
|
|
48
48
|
threshold: float = 0.25
|
|
@@ -111,11 +111,18 @@ class GroundingDINO(Template):
|
|
|
111
111
|
attributes (dict[str, Any]): Dictionary containing configuration parameters.
|
|
112
112
|
"""
|
|
113
113
|
super().__init__(attributes)
|
|
114
|
-
self.
|
|
114
|
+
self.initialize()
|
|
115
|
+
|
|
116
|
+
def initialize(self) -> None:
|
|
117
|
+
"""Initializes the template's common state for creation or reset.
|
|
118
|
+
|
|
119
|
+
This method is called by both `__init__` and `reset_state` to ensure
|
|
120
|
+
a consistent state. Can be overriden by subclasses for specific behaviour.
|
|
121
|
+
"""
|
|
115
122
|
self.processor = AutoProcessor.from_pretrained(
|
|
116
123
|
self.attributes.model_path, cache_dir=self.attributes.model_cache_dir
|
|
117
124
|
)
|
|
118
|
-
self.model = self._set_model().to(self.device)
|
|
125
|
+
self.model = self._set_model().to(self.attributes.device)
|
|
119
126
|
self.max_tokens = self.processor.tokenizer.model_max_length
|
|
120
127
|
self.text_input = self.validate_and_format_text_input(self.attributes.text_input)
|
|
121
128
|
|
|
@@ -171,7 +178,7 @@ class GroundingDINO(Template):
|
|
|
171
178
|
images=image_packet.content,
|
|
172
179
|
text=self.text_input,
|
|
173
180
|
return_tensors="pt",
|
|
174
|
-
).to(self.device)
|
|
181
|
+
).to(self.attributes.device)
|
|
175
182
|
|
|
176
183
|
with torch.no_grad():
|
|
177
184
|
outputs = self.model(**inputs)
|
|
@@ -350,19 +357,32 @@ class GroundingDINO(Template):
|
|
|
350
357
|
|
|
351
358
|
return container
|
|
352
359
|
|
|
353
|
-
|
|
360
|
+
@staticmethod
|
|
361
|
+
def clear_memory() -> None:
|
|
354
362
|
"""Clears memory to free up resources.
|
|
355
363
|
|
|
356
364
|
This method performs garbage collection and clears GPU memory (if applicable) to prevent memory leaks
|
|
357
365
|
and ensure efficient resource usage.
|
|
358
366
|
"""
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
gc.collect()
|
|
362
|
-
if self.attributes.device == "cuda":
|
|
367
|
+
gc.collect()
|
|
368
|
+
if torch.cuda.is_available():
|
|
363
369
|
torch.cuda.empty_cache()
|
|
364
|
-
torch.cuda.ipc_collect()
|
|
365
370
|
|
|
366
371
|
def reset_state(self, template_name: str | None = None) -> None:
|
|
367
|
-
|
|
368
|
-
|
|
372
|
+
"""Releases the pipeline and processor from memory and re-instantiates the template.
|
|
373
|
+
|
|
374
|
+
Args:
|
|
375
|
+
template_name (str | None, optional): The name of the template instance being reset. Defaults to None.
|
|
376
|
+
"""
|
|
377
|
+
_ = template_name
|
|
378
|
+
|
|
379
|
+
if hasattr(self, "model") and self.model is not None:
|
|
380
|
+
self.model.to("cpu")
|
|
381
|
+
del self.model
|
|
382
|
+
|
|
383
|
+
if hasattr(self, "processor"):
|
|
384
|
+
del self.processor
|
|
385
|
+
|
|
386
|
+
self.clear_memory()
|
|
387
|
+
self.initialize()
|
|
388
|
+
self.logger.info(f"Reset template instance `{self.instance_name}`")
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import importlib
|
|
3
|
+
from typing import Callable
|
|
4
|
+
|
|
5
|
+
_root_lib_path = "sinapsis_huggingface_hub.templates"
|
|
6
|
+
|
|
7
|
+
_template_lookup = {
|
|
8
|
+
"HuggingFaceDownloader": f"{_root_lib_path}.huggingface_downloader",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def __getattr__(name: str) -> Callable:
|
|
13
|
+
if name in _template_lookup:
|
|
14
|
+
module = importlib.import_module(_template_lookup[name])
|
|
15
|
+
return getattr(module, name)
|
|
16
|
+
raise AttributeError(f"template `{name}` not found in {_root_lib_path}")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
__all__ = list(_template_lookup.keys())
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from huggingface_hub import snapshot_download
|
|
6
|
+
from pydantic import Field
|
|
7
|
+
from sinapsis_core.data_containers.data_packet import DataContainer
|
|
8
|
+
from sinapsis_core.template_base import Template
|
|
9
|
+
from sinapsis_core.template_base.base_models import TemplateAttributes, TemplateAttributeType, UIPropertiesMetadata
|
|
10
|
+
from sinapsis_core.utils.env_var_keys import SINAPSIS_CACHE_DIR
|
|
11
|
+
from sinapsis_huggingface_transformers.helpers.tags import Tags
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class HuggingFaceDownloaderAttributes(TemplateAttributes):
|
|
15
|
+
"""Defines the configuration for downloading a repository snapshot from the Hugging Face Hub.
|
|
16
|
+
|
|
17
|
+
Attributes:
|
|
18
|
+
repo_id (str): The repository ID from the Hub (e.g., "stabilityai/stable-diffusion-2-1").
|
|
19
|
+
repo_type (Literal["dataset", "space", "model"]): The type of the repository.
|
|
20
|
+
revision (str | None): The specific model version to use (e.g., a branch name, tag, or commit hash).
|
|
21
|
+
cache_dir (str): The directory where downloaded files will be cached.
|
|
22
|
+
allow_patterns (list[str] | str | None): A pattern or list of patterns to specify which files to download.
|
|
23
|
+
ignore_patterns (list[str] | str | None): A pattern or list of patterns to specify which files to ignore.
|
|
24
|
+
max_workers (int): The maximum number of threads to use for parallel downloads.
|
|
25
|
+
force_download (bool): If True, forces the repository to be re-downloaded even if it's already cached.
|
|
26
|
+
proxies (dict): A dictionary of proxy servers to use for the download.
|
|
27
|
+
local_files_only (bool): If True, the function will only look for the files in the cache and will not
|
|
28
|
+
access the network.
|
|
29
|
+
etag_timeout (float): The timeout in seconds for checking the ETag of the files.
|
|
30
|
+
resume_download (bool): If True, resumes an interrupted download.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
repo_id: str
|
|
34
|
+
repo_type: Literal["dataset", "space", "model"] = "model"
|
|
35
|
+
revision: str | None = None
|
|
36
|
+
cache_dir: str = str(SINAPSIS_CACHE_DIR)
|
|
37
|
+
allow_patterns: list[str] | str | None = None
|
|
38
|
+
ignore_patterns: list[str] | str | None = None
|
|
39
|
+
max_workers: int = 8
|
|
40
|
+
force_download: bool = False
|
|
41
|
+
proxies: dict = Field(default_factory=dict)
|
|
42
|
+
local_files_only: bool = False
|
|
43
|
+
etag_timeout: float = 10.0
|
|
44
|
+
resume_download: bool = False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class HuggingFaceDownloader(Template):
|
|
48
|
+
"""A Sinapsis Template that downloads a repository snapshot from the Hugging Face Hub."""
|
|
49
|
+
|
|
50
|
+
AttributesBaseModel = HuggingFaceDownloaderAttributes
|
|
51
|
+
UIProperties = UIPropertiesMetadata(
|
|
52
|
+
category="Hugging Face Hub",
|
|
53
|
+
tags=[Tags.HUGGINGFACE, Tags.MODELS],
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def __init__(self, attributes: TemplateAttributeType) -> None:
|
|
57
|
+
super().__init__(attributes)
|
|
58
|
+
self.logger.info(f"Starting download of {self.attributes.repo_id} to {self.attributes.cache_dir}")
|
|
59
|
+
self.path = snapshot_download(**self.attributes.model_dump(exclude_none=True, exclude={"metadata"}))
|
|
60
|
+
|
|
61
|
+
def execute(self, container: DataContainer) -> DataContainer:
|
|
62
|
+
"""Injects the local directory path of the downloaded repository into the data container.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
container (DataContainer): The data container to which the directory path will be added.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
DataContainer: The updated data container, now containing the directory path.
|
|
69
|
+
"""
|
|
70
|
+
self._set_generic_data(container, self.path)
|
|
71
|
+
return container
|
|
File without changes
|
|
@@ -40,6 +40,7 @@ class ImageToTextTransformersAttributes(TransformersBaseAttributes):
|
|
|
40
40
|
such as `max_new_tokens`.
|
|
41
41
|
"""
|
|
42
42
|
|
|
43
|
+
model_path: Literal["Qwen/Qwen-Image"] = "Qwen/Qwen-Image"
|
|
43
44
|
inference_kwargs: ImageToTextInferenceKwargs = Field(default_factory=ImageToTextInferenceKwargs)
|
|
44
45
|
|
|
45
46
|
|
|
@@ -33,7 +33,7 @@ class PaliGemmaBaseAttributes(TemplateAttributes):
|
|
|
33
33
|
torch_dtype (Literal["float16", "float32"]): Model precision type. Defaults to float16.
|
|
34
34
|
"""
|
|
35
35
|
|
|
36
|
-
model_path:
|
|
36
|
+
model_path: Literal["google/paligemma2-3b-pt-224"] = "google/paligemma2-3b-pt-224"
|
|
37
37
|
processor_path: str
|
|
38
38
|
model_cache_dir: str = str(SINAPSIS_CACHE_DIR)
|
|
39
39
|
device: Literal["cuda", "cpu"] = "cpu"
|
|
@@ -41,6 +41,7 @@ class SpeechToTextTransformersAttributes(TransformersBaseAttributes):
|
|
|
41
41
|
such as `return_timestamps`.
|
|
42
42
|
"""
|
|
43
43
|
|
|
44
|
+
model_path: Literal["openai/whisper-small"] = "openai/whisper-small"
|
|
44
45
|
inference_kwargs: SpeechToTextInferenceKwargs = Field(default_factory=SpeechToTextInferenceKwargs)
|
|
45
46
|
|
|
46
47
|
|
|
@@ -39,6 +39,7 @@ class SummarizationTransformersAttributes(TransformersBaseAttributes):
|
|
|
39
39
|
inference_kwargs: Task-specific parameters for the summarization pipeline,
|
|
40
40
|
such as `clean_up_tokenization_spaces`.
|
|
41
41
|
"""
|
|
42
|
+
model_path: Literal["facebook/bart-large-cnn", "google/pegasus-xsum", "Falconsai/text_summarization", "facebook/bart-large-xsum"] = "facebook/bart-large-cnn"
|
|
42
43
|
|
|
43
44
|
inference_kwargs: SummarizationInferenceKwargs = Field(default_factory=SummarizationInferenceKwargs)
|
|
44
45
|
|
|
@@ -29,6 +29,7 @@ class TextToSpeechAttributes(TransformersBaseAttributes):
|
|
|
29
29
|
input text into smaller chunks. If not specified, sentences will be split
|
|
30
30
|
based on punctuation.
|
|
31
31
|
"""
|
|
32
|
+
model_path: Literal["suno/bark", "suno/bark-small", "ResembleAI/chatterbox"] = "suno/bark"
|
|
32
33
|
|
|
33
34
|
use_embeddings: bool = False
|
|
34
35
|
sample_rate: int | None = None
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sinapsis-huggingface"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.13"
|
|
4
4
|
description = "Package for HuggingFace-based templates"
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "SinapsisAI", email = "dev@sinapsis.tech"},
|
|
@@ -28,6 +28,7 @@ all = [
|
|
|
28
28
|
"sinapsis-huggingface-embeddings",
|
|
29
29
|
"sinapsis-huggingface-grounding-dino",
|
|
30
30
|
"sinapsis-huggingface-transformers",
|
|
31
|
+
"sinapsis-huggingface-hub[all]",
|
|
31
32
|
"sinapsis-huggingface[gradio-app,sinapsis-data-writers]",
|
|
32
33
|
]
|
|
33
34
|
sinapsis-data-writers = [
|
|
@@ -52,6 +53,7 @@ sinapsis-huggingface-transformers= {workspace = true}
|
|
|
52
53
|
sinapsis-huggingface-embeddings = {workspace = true}
|
|
53
54
|
sinapsis-huggingface-grounding-dino = { workspace = true }
|
|
54
55
|
sinapsis-huggingface-diffusers = { workspace = true }
|
|
56
|
+
sinapsis-huggingface-hub = { workspace = true }
|
|
55
57
|
sinapsis-huggingface = { workspace = true }
|
|
56
58
|
|
|
57
59
|
[[tool.uv.index]]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|