sander-wood commited on
Commit
0a4265e
1 Parent(s): 5883c77

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -67
app.py CHANGED
@@ -5,78 +5,45 @@ from unidecode import unidecode
5
  from transformers import GPT2LMHeadModel
6
  from samplings import top_p_sampling, temperature_sampling
7
 
8
- device = torch.device("cpu")
9
 
10
  description = """
11
  <div>
12
- <a style="display:inline-block" href='https://github.com/suno-ai/bark'><img src='https://img.shields.io/github/stars/suno-ai/bark?style=social' /></a>
13
- <a style='display:inline-block' href='https://discord.gg/J2B2vsjKuE'><img src='https://dcbadge.vercel.app/api/server/J2B2vsjKuE?compact=true&style=flat' /></a>
14
- <a style="display:inline-block; margin-left: 1em" href="https://huggingface.co/spaces/suno/bark?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space%20to%20skip%20the%20queue-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
 
15
  </div>
16
- Bark is a universal text-to-audio model created by [Suno](www.suno.ai), with code publicly available [here](https://github.com/suno-ai/bark). \
17
- Bark can generate highly realistic, multilingual speech as well as other audio - including music, background noise and simple sound effects. \
18
- This demo should be used for research purposes only. Commercial use is strictly prohibited. \
19
- The model output is not censored and the authors do not endorse the opinions in the generated content. \
20
- Use at your own risk.
21
- """
22
 
23
- article = """
24
- ## 🌎 Foreign Language
25
- Bark supports various languages out-of-the-box and automatically determines language from input text. \
26
- When prompted with code-switched text, Bark will even attempt to employ the native accent for the respective languages in the same voice.
27
- Try the prompt:
28
- ```
29
- Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.
30
- ```
31
- ## 🤭 Non-Speech Sounds
32
- Below is a list of some known non-speech sounds, but we are finding more every day. \
33
- Please let us know if you find patterns that work particularly well on Discord!
34
- * [laughter]
35
- * [laughs]
36
- * [sighs]
37
- * [music]
38
- * [gasps]
39
- * [clears throat]
40
- * — or ... for hesitations
41
- * for song lyrics
42
- * capitalization for emphasis of a word
43
- * MAN/WOMAN: for bias towards speaker
44
- Try the prompt:
45
- ```
46
- " [clears throat] Hello, my name is Suno. And, uh and I like pizza. [laughs] But I also have other interests such as... ♪ singing ♪."
47
- ```
48
- ## 🎶 Music
49
- Bark can generate all types of audio, and, in principle, doesn't see a difference between speech and music. \
50
- Sometimes Bark chooses to generate text as music, but you can help it out by adding music notes around your lyrics.
51
- Try the prompt:
52
- ```
53
- ♪ In the jungle, the mighty jungle, the lion barks tonight ♪
54
- ```
55
- ## 🧬 Voice Cloning
56
- Bark has the capability to fully clone voices - including tone, pitch, emotion and prosody. \
57
- The model also attempts to preserve music, ambient noise, etc. from input audio. \
58
- However, to mitigate misuse of this technology, we limit the audio history prompts to a limited set of Suno-provided, fully synthetic options to choose from.
59
- ## 👥 Speaker Prompts
60
- You can provide certain speaker prompts such as NARRATOR, MAN, WOMAN, etc. \
61
- Please note that these are not always respected, especially if a conflicting audio history prompt is given.
62
- Try the prompt:
63
- ```
64
- WOMAN: I would like an oatmilk latte please.
65
- MAN: Wow, that's expensive!
66
- ```
67
- ## Details
68
- Bark model by [Suno](https://suno.ai/), including official [code](https://github.com/suno-ai/bark) and model weights. \
69
- Gradio demo supported by 🤗 Hugging Face. Bark is licensed under a non-commercial license: CC-BY 4.0 NC, see details on [GitHub](https://github.com/suno-ai/bark).
70
  """
71
 
72
- # examples = [
73
- # "Jazz standard in Minor key with a swing feel.",
74
- # "Jazz standard in Major key with a fast tempo.",
75
- # "Jazz standard in Blues form with a soulfoul melody.",
76
- # "a painting of a starry night with the moon in the sky",
77
- # "a green field with a blue sky and clouds",
78
- # "a beach with a castle on top of it"
79
- # ]
80
 
81
  class ABCTokenizer():
82
  def __init__(self):
@@ -187,5 +154,4 @@ gr.Interface(generate_abc,
187
  [input_control_codes, input_prefix, input_num_tunes, input_max_length, input_top_p, input_temperature, input_seed],
188
  output_abc,
189
  title="TunesFormer: Forming Tunes with Control Codes",
190
- description=description,
191
- article=article).launch()
 
5
  from transformers import GPT2LMHeadModel
6
  from samplings import top_p_sampling, temperature_sampling
7
 
8
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
 
10
  description = """
11
  <div>
12
+
13
+ <a style="display:inline-block" href='https://github.com/sander-wood/tunesformer'><img src='https://img.shields.io/github/stars/sander-wood/tunesformer?style=social' /></a>
14
+ <a style="display:inline-block" href="https://huggingface.co/datasets/sander-wood/massive_abcnotation_dataset"><img src="https://img.shields.io/badge/huggingface-dataset-ffcc66.svg"></a>
15
+ <a style="display:inline-block" href="https://arxiv.org/pdf/2301.02884.pdf"><img src="https://img.shields.io/badge/arXiv-2301.02884-b31b1b.svg"></a>
16
  </div>
 
 
 
 
 
 
17
 
18
+ ## ℹ️ How to use this demo?
19
+ 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)
20
+ 2. Enter the prefix of the generated music. You can set the ABC header (i.e., note length, tempo, meter, and key) and the beginning of the music. (optional)
21
+ 2. You can set the parameters (i.e., number of tunes, maximum length, top-p, temperature, and random seed) for the generation. (optional)
22
+ 3. Click "Submit" and wait for the result.
23
+ 4. The generated ABC notation can be converted to MIDI or PDF using [EasyABC](https://sourceforge.net/projects/easyabc/), you can also use this [online renderer](https://ldzhangyx.github.io/abc/) to render the ABC notation.
24
+
25
+ ## 📝 Control Codes
26
+ There are 3 types of control codes: section bar `[BARS_NB]`, `[SECS_NS]`, and similarity `[SIM_EDS]`. The control codes can be used to set the musical form of the generated music:
27
+
28
+ - `[BARS_NB]`: controls the number of bars in a section of the melody. For example, users could specify that they want a section to contain 8 bars, and TunesFormer would generate a section that fits within that structure. It counts on the bar symbol `|`. The value of `NB` ranges from 1 to 32, where 1 means one bar and 32 means thirty-two bars.
29
+ - `[SECS_NS]`: controls the number of sections in the entire melody. This can be used to create a sense of structure and coherence within the melody, as different sections can be used to create musical themes or motifs. It counts on several symbols that are commonly used in ABC notation and can be used to represent section boundaries: `[|`,`||`,`|]`,`|:`,`::`, and `:|`. The value of `NS` ranges from 1 to 8, where 1 means one section and 8 means eight sections.
30
+ - `[SIM_EDS]`: controls the similarity between the generated music and the prefix. The value of `EDS` is the edit distance similarity level between the current section and a previous section in the melody. The value of EDS ranges from 0 to 10, where 0 means no similarity and 10 means the same section.
31
+
32
+ To provide a clearer understanding of the control codes, we provide an example below:
33
+
34
+ `[SECS_3][BARS_8][SIM_3][BARS_8][SIM_10][SIM_3][BARS_8]`
35
+
36
+ The first control code `[SECS_3]` specifies there are 3 sections in the tune, and the following control code `[BARS_8]` indicates the first section has 8 bars. The next two control codes `[SIM_3]` and `[BAR_8]` indicate that the EDS between section II and section I is approximately 0.3, and section II has 8 bars. The last three control codes `[SIM_10]`, `[SIM_3]` and `[BARS_8]` specify that section III is identical to section I while dissimilar to section II, and has 8 bars.
37
+
38
+ ## ❕Notice
39
+ - If the prefix is given, you must also provide the control codes.
40
+ - 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).
41
+ - 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).
42
+ - 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).
43
+
44
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  """
46
 
 
 
 
 
 
 
 
 
47
 
48
  class ABCTokenizer():
49
  def __init__(self):
 
154
  [input_control_codes, input_prefix, input_num_tunes, input_max_length, input_top_p, input_temperature, input_seed],
155
  output_abc,
156
  title="TunesFormer: Forming Tunes with Control Codes",
157
+ description=description).launch()