Spaces:
Runtime error
Runtime error
sander-wood
commited on
Commit
•
d2803de
1
Parent(s):
8dcbf13
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ description = """
|
|
31 |
## ℹ️ How to use this demo?
|
32 |
1. Enter the control codes to set the musical form of the generated music. For details, please refer to the below "Control Codes" section. (optional)
|
33 |
2. Enter the prompt of the generated music. You can set the control codes to set the musical form, ABC header (i.e., note length, tempo, meter, and key) and the motif of the melody. (optional)
|
34 |
-
2. You can set the parameters (i.e., number of tunes, maximum patch, top-p, top-k, temperature
|
35 |
3. Click "Submit" and wait for the result.
|
36 |
4. The generated ABC notation can be played or edited using [EasyABC]([ABC Sheet Music Editor - EasyABC](https://easyabc.sourceforge.net/), you can also use this [Online ABC Player](https://abc.rectanglered.com/) to render the tune.
|
37 |
|
@@ -48,13 +48,14 @@ Inspired by [CTRL](https://huggingface.co/ctrl), we incorporate control codes in
|
|
48 |
```
|
49 |
where $|c|$ and $|p|$ are the string lengths of the two sections. It is discretized into 11 levels, ranging from no match at all to an exact match (e.g., `E:0` for no similarity, and `E:10` for an exact match).
|
50 |
|
51 |
-
## ❕
|
52 |
-
|
53 |
-
- The order of the ABC header cannot be changed (i.e., note length, tempo, meter, and key), and also do not support other headers (e.g., composer, title, etc.) as they are not used in the model. For details, please refer to the official [ABC notation](https://abcnotation.com/wiki/abc:standard:v2.1#description_of_information_fields).
|
54 |
-
- The demo is based on GPT2-small and trained from scratch on the [Massive ABC Notation Dataset](https://huggingface.co/datasets/sander-wood/massive_abcnotation_dataset).
|
55 |
-
- The demo is still in the early stage, and the generated music is not perfect. If you have any suggestions, please feel free to contact me via [email](mailto:shangda@mail.ccom.edu.cn).
|
56 |
|
|
|
57 |
|
|
|
|
|
|
|
58 |
"""
|
59 |
|
60 |
class Patchilizer:
|
@@ -305,7 +306,14 @@ class TunesFormer(PreTrainedModel):
|
|
305 |
|
306 |
return generated_patch, n_seed
|
307 |
|
308 |
-
def generate_abc(prompt,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
|
310 |
if torch.cuda.is_available():
|
311 |
device = torch.device("cuda")
|
@@ -419,7 +427,7 @@ M:3/4
|
|
419 |
K:D
|
420 |
de |"D" """
|
421 |
|
422 |
-
input_prompt = gr.inputs.Textbox(lines=5, label="
|
423 |
input_num_tunes = gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Number of Tunes")
|
424 |
input_max_patch = gr.inputs.Slider(minimum=10, maximum=128, step=1, default=128, label="Max Patch")
|
425 |
input_top_p = gr.inputs.Slider(minimum=0.0, maximum=1.0, step=0.05, default=0.8, label="Top P")
|
|
|
31 |
## ℹ️ How to use this demo?
|
32 |
1. Enter the control codes to set the musical form of the generated music. For details, please refer to the below "Control Codes" section. (optional)
|
33 |
2. Enter the prompt of the generated music. You can set the control codes to set the musical form, ABC header (i.e., note length, tempo, meter, and key) and the motif of the melody. (optional)
|
34 |
+
2. You can set the parameters (i.e., number of tunes, maximum patch, top-p, top-k, temperature and random seed) for the generation. (optional)
|
35 |
3. Click "Submit" and wait for the result.
|
36 |
4. The generated ABC notation can be played or edited using [EasyABC]([ABC Sheet Music Editor - EasyABC](https://easyabc.sourceforge.net/), you can also use this [Online ABC Player](https://abc.rectanglered.com/) to render the tune.
|
37 |
|
|
|
48 |
```
|
49 |
where $|c|$ and $|p|$ are the string lengths of the two sections. It is discretized into 11 levels, ranging from no match at all to an exact match (e.g., `E:0` for no similarity, and `E:10` for an exact match).
|
50 |
|
51 |
+
## ❕Caution
|
52 |
+
ABC notation is a specialized notation of representing sheet music, and it follows a specific standard format. When interacting with TunesFormer, all trained ABC notation adheres to these standard formats.
|
|
|
|
|
|
|
53 |
|
54 |
+
If you are unfamiliar with the details of ABC notation, we strongly recommend against manually entering ABC notation. Otherwise, the model may not recognize and generate the music correctly. Inputting incorrect formats might lead to unpredictable outputs or other issues.
|
55 |
|
56 |
+
A general recommendation is to adjust the desired musical structure and form through control codes and ABC header, rather than directly editing the ABC notation itself.
|
57 |
+
|
58 |
+
Please make sure to operate according to the provided formats and guidelines to fully leverage the capabilities of TunesFormer and achieve a satisfying music generation experience.
|
59 |
"""
|
60 |
|
61 |
class Patchilizer:
|
|
|
306 |
|
307 |
return generated_patch, n_seed
|
308 |
|
309 |
+
def generate_abc(prompt,
|
310 |
+
num_tunes,
|
311 |
+
max_patch,
|
312 |
+
top_p,
|
313 |
+
top_k,
|
314 |
+
temperature,
|
315 |
+
seed,
|
316 |
+
show_control_code=True):
|
317 |
|
318 |
if torch.cuda.is_available():
|
319 |
device = torch.device("cuda")
|
|
|
427 |
K:D
|
428 |
de |"D" """
|
429 |
|
430 |
+
input_prompt = gr.inputs.Textbox(lines=5, label="Prompt", default=default_prompt)
|
431 |
input_num_tunes = gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Number of Tunes")
|
432 |
input_max_patch = gr.inputs.Slider(minimum=10, maximum=128, step=1, default=128, label="Max Patch")
|
433 |
input_top_p = gr.inputs.Slider(minimum=0.0, maximum=1.0, step=0.05, default=0.8, label="Top P")
|