ai-simple-engine-api-musicgen 0.0.1__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.
- ai_simple_engine_api_musicgen-0.0.1/LICENSE +19 -0
- ai_simple_engine_api_musicgen-0.0.1/PKG-INFO +19 -0
- ai_simple_engine_api_musicgen-0.0.1/README.md +3 -0
- ai_simple_engine_api_musicgen-0.0.1/pyproject.toml +39 -0
- ai_simple_engine_api_musicgen-0.0.1/src/ai_simple_engine_api_musicgen/__init__.py +84 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-simple-engine-api-musicgen
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: AI Simple Engine API Musicgen Module
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Author: danialcala94
|
|
7
|
+
Author-email: danielalcalavalera@gmail.com
|
|
8
|
+
Requires-Python: >=3.10,<3.12
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Requires-Dist: ai-simple-engine (>=0.1.6,<1.0.0)
|
|
13
|
+
Requires-Dist: ai-simple-engine-musicgen (>=0.0.1,<1.0.0)
|
|
14
|
+
Requires-Dist: torch (==2.5.1)
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# AI Simple Engine API Musicgen Module
|
|
18
|
+
|
|
19
|
+
The module that implements the API for the Musicgen functionality, using the AI Simple Engine `ai-simple-engine`.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ai-simple-engine-api-musicgen"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "AI Simple Engine API Musicgen Module"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "danialcala94", email = "danielalcalavalera@gmail.com"}
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.10,<3.12"
|
|
10
|
+
|
|
11
|
+
[tool.poetry.dependencies]
|
|
12
|
+
# Mandatory
|
|
13
|
+
ai-simple-engine = { version = ">=0.1.6,<1.0.0", optional = false }
|
|
14
|
+
ai-simple-engine-musicgen = { version = ">=0.0.1,<1.0.0", optional = false }
|
|
15
|
+
# TODO: I have to force this manually. Why (?)
|
|
16
|
+
torch = { version = "==2.5.1", source = "pytorch", optional = false }
|
|
17
|
+
# Optional
|
|
18
|
+
|
|
19
|
+
[tool.poetry]
|
|
20
|
+
packages = [{include = "ai_simple_engine_api_musicgen", from = "src"}]
|
|
21
|
+
|
|
22
|
+
[[tool.poetry.source]]
|
|
23
|
+
name = "pytorch"
|
|
24
|
+
url = "https://download.pytorch.org/whl/cu121"
|
|
25
|
+
# url = "https://download.pytorch.org/whl/cu129"
|
|
26
|
+
priority = "explicit"
|
|
27
|
+
|
|
28
|
+
[tool.poetry.group.dev.dependencies]
|
|
29
|
+
pytest = "^8.3.5"
|
|
30
|
+
|
|
31
|
+
[tool.pytest.ini_options]
|
|
32
|
+
markers = [
|
|
33
|
+
"mandatory: mandatory tests for release",
|
|
34
|
+
"additional: exhaustive and demanding tests"
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
39
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The functionality related to the `musicgen` model
|
|
3
|
+
using the AI Simple Engine.
|
|
4
|
+
"""
|
|
5
|
+
from ai_simple_engine.engine import Engine
|
|
6
|
+
from ai_simple_engine.types.audio import Audio
|
|
7
|
+
from ai_simple_engine.models.spec.base import ModelSpec
|
|
8
|
+
from ai_simple_engine.graph.operation.install_model import InstallModel
|
|
9
|
+
from ai_simple_engine.graph.operation.acquire_model import AcquireModel
|
|
10
|
+
from ai_simple_engine_musicgen.operations.generate_music import GenerateMusic
|
|
11
|
+
from ai_simple_engine_musicgen.consts import MUSICGEN_MODEL_FAMILY_NAME
|
|
12
|
+
from ai_simple_engine_musicgen.models.consts import FACEBOOK_MUSICGEN_SMALL
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MusicgenAPI:
|
|
16
|
+
"""
|
|
17
|
+
Class to simplify the way you use the
|
|
18
|
+
`musicgen` functionality.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
engine: Engine
|
|
24
|
+
):
|
|
25
|
+
self._engine: Engine = engine
|
|
26
|
+
"""
|
|
27
|
+
*For internal use only*
|
|
28
|
+
|
|
29
|
+
The engine that will perform the operations.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
async def generate_music(
|
|
33
|
+
self,
|
|
34
|
+
prompt: str,
|
|
35
|
+
duration: float = 5,
|
|
36
|
+
provider: str = 'huggingface',
|
|
37
|
+
) -> Audio:
|
|
38
|
+
"""
|
|
39
|
+
Generate music with the given `prompt` and the
|
|
40
|
+
`duration` provided, using the `provider` for
|
|
41
|
+
the `musicgen` model.
|
|
42
|
+
|
|
43
|
+
The provider must be included in the engine
|
|
44
|
+
given to this class instance or it will raise
|
|
45
|
+
an error when trying to obtain it.
|
|
46
|
+
"""
|
|
47
|
+
max_new_tokens = _duration_to_tokens(duration)
|
|
48
|
+
|
|
49
|
+
music = GenerateMusic(
|
|
50
|
+
model = AcquireModel(
|
|
51
|
+
installed_model = InstallModel(
|
|
52
|
+
spec = ModelSpec(
|
|
53
|
+
family = MUSICGEN_MODEL_FAMILY_NAME,
|
|
54
|
+
provider = provider,
|
|
55
|
+
identifier = FACEBOOK_MUSICGEN_SMALL
|
|
56
|
+
)
|
|
57
|
+
).installed_model
|
|
58
|
+
).model,
|
|
59
|
+
prompt = prompt,
|
|
60
|
+
# duration depends on the tokens => 512 = 10s
|
|
61
|
+
max_new_tokens = max_new_tokens
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return await self._engine.run(
|
|
65
|
+
music.audio
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _duration_to_tokens(
|
|
70
|
+
duration: float
|
|
71
|
+
) -> int:
|
|
72
|
+
"""
|
|
73
|
+
*For internal use only*
|
|
74
|
+
|
|
75
|
+
Get the amount of tokens that the `musicgen`
|
|
76
|
+
model has to generate to provide an audio of
|
|
77
|
+
the given `duration`.
|
|
78
|
+
|
|
79
|
+
This model generates around 50 tokes per
|
|
80
|
+
second of audio.
|
|
81
|
+
"""
|
|
82
|
+
TOKENS_PER_SECOND = 50
|
|
83
|
+
|
|
84
|
+
return round(duration * TOKENS_PER_SECOND)
|