Audio-to-Audio
Diffusers
Safetensors
SpanSynthEditPipeline
audio
music
midi
midi-to-audio
flow-matching
Instructions to use mimbres/spansynth-edit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use mimbres/spansynth-edit with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("mimbres/spansynth-edit", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Use a string pipeline class with explicit custom loading
Browse files- README.md +6 -2
- model_index.json +1 -4
- pipeline.py +0 -7
README.md
CHANGED
|
@@ -80,6 +80,7 @@ from diffusers import DiffusionPipeline
|
|
| 80 |
|
| 81 |
pipe = DiffusionPipeline.from_pretrained(
|
| 82 |
'mimbres/spansynth-edit',
|
|
|
|
| 83 |
trust_remote_code=True,
|
| 84 |
).to('cuda')
|
| 85 |
result = pipe(
|
|
@@ -94,12 +95,15 @@ sf.write('edited.wav', result.audios[0, 0], result.sample_rate, subtype='FLOAT')
|
|
| 94 |
Use `.to('mps')` for Apple Silicon or `.to('cpu')` for CPU. For FlowEdit, add
|
| 95 |
`method='flowedit'` and `source_midi` pointing to the original score. The pipeline
|
| 96 |
also accepts the crop, region, MIDI offset, and context options described below.
|
| 97 |
-
This custom pipeline uses the installed `spansynth` package.
|
|
|
|
| 98 |
Save and reopen the pipeline locally with:
|
| 99 |
|
| 100 |
```python
|
| 101 |
pipe.save_pretrained('saved-pipeline')
|
| 102 |
-
pipe = DiffusionPipeline.from_pretrained(
|
|
|
|
|
|
|
| 103 |
```
|
| 104 |
|
| 105 |
## Try an example
|
|
|
|
| 80 |
|
| 81 |
pipe = DiffusionPipeline.from_pretrained(
|
| 82 |
'mimbres/spansynth-edit',
|
| 83 |
+
custom_pipeline='pipeline',
|
| 84 |
trust_remote_code=True,
|
| 85 |
).to('cuda')
|
| 86 |
result = pipe(
|
|
|
|
| 95 |
Use `.to('mps')` for Apple Silicon or `.to('cpu')` for CPU. For FlowEdit, add
|
| 96 |
`method='flowedit'` and `source_midi` pointing to the original score. The pipeline
|
| 97 |
also accepts the crop, region, MIDI offset, and context options described below.
|
| 98 |
+
This custom pipeline uses the installed `spansynth` package. Pass
|
| 99 |
+
`custom_pipeline='pipeline'` to load the repository's `pipeline.py` implementation.
|
| 100 |
Save and reopen the pipeline locally with:
|
| 101 |
|
| 102 |
```python
|
| 103 |
pipe.save_pretrained('saved-pipeline')
|
| 104 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 105 |
+
'saved-pipeline', custom_pipeline='pipeline', trust_remote_code=True,
|
| 106 |
+
)
|
| 107 |
```
|
| 108 |
|
| 109 |
## Try an example
|
model_index.json
CHANGED
|
@@ -1,8 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"_class_name":
|
| 3 |
-
"pipeline",
|
| 4 |
-
"SpanSynthEditPipeline"
|
| 5 |
-
],
|
| 6 |
"_diffusers_version": "0.40.0",
|
| 7 |
"codec": [
|
| 8 |
"spansynth.diffusers_models",
|
|
|
|
| 1 |
{
|
| 2 |
+
"_class_name": "SpanSynthEditPipeline",
|
|
|
|
|
|
|
|
|
|
| 3 |
"_diffusers_version": "0.40.0",
|
| 4 |
"codec": [
|
| 5 |
"spansynth.diffusers_models",
|
pipeline.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
"""MIDI-guided music synthesis and editing through Diffusers."""
|
| 2 |
|
| 3 |
from dataclasses import dataclass
|
| 4 |
-
import json
|
| 5 |
import math
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
@@ -54,12 +53,6 @@ class SpanSynthEditPipeline(DiffusionPipeline):
|
|
| 54 |
super().__init__()
|
| 55 |
self.register_modules(transformer=transformer, codec=codec)
|
| 56 |
|
| 57 |
-
def to_json_string(self):
|
| 58 |
-
"""Identify the saved custom pipeline for Diffusers' standard loader."""
|
| 59 |
-
config = json.loads(super().to_json_string())
|
| 60 |
-
config["_class_name"] = ["pipeline", self.__class__.__name__]
|
| 61 |
-
return json.dumps(config, indent=2, sort_keys=True) + "\n"
|
| 62 |
-
|
| 63 |
def save_pretrained(self, save_directory: str | Path, **kwargs):
|
| 64 |
"""Save weights and the code entries required by the Hub's custom loader.
|
| 65 |
|
|
|
|
| 1 |
"""MIDI-guided music synthesis and editing through Diffusers."""
|
| 2 |
|
| 3 |
from dataclasses import dataclass
|
|
|
|
| 4 |
import math
|
| 5 |
from pathlib import Path
|
| 6 |
|
|
|
|
| 53 |
super().__init__()
|
| 54 |
self.register_modules(transformer=transformer, codec=codec)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
def save_pretrained(self, save_directory: str | Path, **kwargs):
|
| 57 |
"""Save weights and the code entries required by the Hub's custom loader.
|
| 58 |
|