Tonic commited on
Commit
e8edce5
·
unverified ·
1 Parent(s): 91d712c

add description and join us gradio interface

Browse files
Files changed (3) hide show
  1. build_chord_maps.py +0 -92
  2. extract_chords.py +0 -73
  3. main.py +19 -4
build_chord_maps.py DELETED
@@ -1,92 +0,0 @@
1
- # Copyright (c) Meta Platforms, Inc. and affiliates.
2
- # All rights reserved.
3
- #
4
- # This source code is licensed under the license found in the
5
- # LICENSE file in the root directory of this source tree.
6
- import os
7
- import pickle
8
- from tqdm import tqdm
9
- import argparse
10
-
11
-
12
- def parse_args():
13
- parser = argparse.ArgumentParser()
14
- parser.add_argument('--chords_folder', type=str, required=True,
15
- help='path to directory containing parsed chords files')
16
- parser.add_argument('--output_directory', type=str, required=False,
17
- help='path to output directory to generate code maps to, \
18
- if not given - chords_folder would be used', default='')
19
- parser.add_argument('--path_to_pre_defined_map', type=str, required=False,
20
- help='for evaluation purpose, use pre-defined chord-to-index map', default='')
21
- args = parser.parse_args()
22
- return args
23
-
24
-
25
- def get_chord_dict(chord_folder: str):
26
- chord_dict = {}
27
- distinct_chords = set()
28
-
29
- chord_to_index = {} # Mapping between chord and index
30
- index_counter = 0
31
-
32
- for filename in tqdm(os.listdir(chord_folder)):
33
- if filename.endswith(".chords"):
34
- idx = filename.split(".")[0]
35
-
36
- with open(os.path.join(chord_folder, filename), "rb") as file:
37
- chord_data = pickle.load(file)
38
-
39
- for chord, _ in chord_data:
40
- distinct_chords.add(chord)
41
- if chord not in chord_to_index:
42
- chord_to_index[chord] = index_counter
43
- index_counter += 1
44
-
45
- chord_dict[idx] = chord_data
46
- chord_to_index["UNK"] = index_counter
47
- return chord_dict, distinct_chords, chord_to_index
48
-
49
-
50
- def get_predefined_chord_to_index_map(path_to_chords_to_index_map: str):
51
- def inner(chord_folder: str):
52
- chords_to_index = pickle.load(open(path_to_chords_to_index_map, "rb"))
53
- distinct_chords = set(chords_to_index.keys())
54
- chord_dict = {}
55
- for filename in tqdm(os.listdir(chord_folder), desc=f'iterating: {chord_folder}'):
56
- if filename.endswith(".chords"):
57
- idx = filename.split(".")[0]
58
-
59
- with open(os.path.join(chord_folder, filename), "rb") as file:
60
- chord_data = pickle.load(file)
61
-
62
- chord_dict[idx] = chord_data
63
- return chord_dict, distinct_chords, chords_to_index
64
- return inner
65
-
66
-
67
- if __name__ == "__main__":
68
- '''This script processes and maps chord data from a directory of parsed chords files,
69
- generating two output files: a combined chord dictionary and a chord-to-index mapping.'''
70
- args = parse_args()
71
- chord_folder = args.chords_folder
72
- output_dir = args.output_directory
73
- if output_dir == '':
74
- output_dir = chord_folder
75
- func = get_chord_dict
76
- if args.path_to_pre_defined_map != "":
77
- func = get_predefined_chord_to_index_map(args.path_to_pre_defined_map)
78
-
79
- chord_dict, distinct_chords, chord_to_index = func(chord_folder)
80
-
81
- # Save the combined chord dictionary as a pickle file
82
- combined_filename = os.path.join(output_dir, "combined_chord_dict.pkl")
83
- with open(combined_filename, "wb") as file:
84
- pickle.dump(chord_dict, file)
85
-
86
- # Save the chord-to-index mapping as a pickle file
87
- mapping_filename = os.path.join(output_dir, "chord_to_index_mapping.pkl")
88
- with open(mapping_filename, "wb") as file:
89
- pickle.dump(chord_to_index, file)
90
-
91
- print("Number of distinct chords:", len(distinct_chords))
92
- print("Chord dictionary:", chord_to_index)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
extract_chords.py DELETED
@@ -1,73 +0,0 @@
1
- # Env - chords_extraction on devfair
2
-
3
- import pickle
4
- import argparse
5
- from chord_extractor.extractors import Chordino # type: ignore
6
- from chord_extractor import clear_conversion_cache, LabelledChordSequence # type: ignore
7
- import os
8
- from tqdm import tqdm
9
-
10
-
11
- def parse_args():
12
- parser = argparse.ArgumentParser()
13
- parser.add_argument('--src_jsonl_file', type=str, required=True,
14
- help='abs path to .jsonl file containing list of absolute file paths seperated by new line')
15
- parser.add_argument('--target_output_dir', type=str, required=True,
16
- help='target directory to save parsed chord files to, individual files will be saved inside')
17
- parser.add_argument("--override", action="store_true")
18
- args = parser.parse_args()
19
- return args
20
-
21
-
22
- def save_to_db_cb(tgt_dir: str):
23
- # Every time one of the files has had chords extracted, receive the chords here
24
- # along with the name of the original file and then run some logic here, e.g. to
25
- # save the latest data to DB
26
- def inner(results: LabelledChordSequence):
27
- path = results.id.split(".wav")
28
-
29
- sequence = [(item.chord, item.timestamp) for item in results.sequence]
30
-
31
- if len(path) != 2:
32
- print("Something")
33
- print(path)
34
- else:
35
- file_idx = path[0].split("/")[-1]
36
- with open(f"{tgt_dir}/{file_idx}.chords", "wb") as f:
37
- # dump the object to the file
38
- pickle.dump(sequence, f)
39
- return inner
40
-
41
-
42
- if __name__ == "__main__":
43
- '''This script extracts chord data from a list of audio files using the Chordino extractor,
44
- and saves the extracted chords to individual files in a target directory.'''
45
- print("parsed args")
46
- args = parse_args()
47
- files_to_extract_from = list()
48
- with open(args.src_jsonl_file, "r") as json_file:
49
- for line in tqdm(json_file.readlines()):
50
- # fpath = json.loads(line.replace("\n", ""))['path']
51
- fpath = line.replace("\n", "")
52
- if not args.override:
53
- fname = fpath.split("/")[-1].replace(".wav", ".chords")
54
- if os.path.exists(f"{args.target_output_dir}/{fname}"):
55
- continue
56
- files_to_extract_from.append(line.replace("\n", ""))
57
-
58
- print(f"num files to parse: {len(files_to_extract_from)}")
59
-
60
- chordino = Chordino()
61
-
62
- # Optionally clear cache of file conversions (e.g. wav files that have been converted from midi)
63
- clear_conversion_cache()
64
-
65
- # Run bulk extraction
66
- res = chordino.extract_many(
67
- files_to_extract_from,
68
- callback=save_to_db_cb(args.target_output_dir),
69
- num_extractors=80,
70
- num_preprocessors=80,
71
- max_files_in_cache=400,
72
- stop_on_error=False,
73
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py CHANGED
@@ -16,6 +16,17 @@ from audiocraft.models import JASCO
16
  import os
17
  from huggingface_hub import login
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  hf_token = os.environ.get('HFTOKEN')
20
  if hf_token:
21
  login(token=hf_token)
@@ -256,10 +267,14 @@ def predict_full(model, text, chords_sym, melody_file,
256
  return wavs
257
 
258
  with gr.Blocks() as demo:
259
- gr.Markdown("""
260
- # JASCO - Text-to-Music Generation with Temporal Control
261
- Generate 10-second music clips using text descriptions and temporal controls (chords, drums, melody).
262
- """)
 
 
 
 
263
 
264
  with gr.Row():
265
  with gr.Column():
 
16
  import os
17
  from huggingface_hub import login
18
 
19
+ title = """# 🙋🏻‍♂️Welcome to 🌟Tonic's 🎼Jasco🎶AudioCraft Demo"""
20
+ description = """Facebook presents JASCO, a temporally controlled text-to-music generation model utilizing both symbolic and audio-based conditions. JASCO can generate high-quality music samples conditioned on global text descriptions along with fine-grained local controls. JASCO is based on the Flow Matching modeling paradigm together with a novel conditioning method, allowing for music generation controlled both locally (e.g., chords) and globally (text description)."""
21
+ join_us = """
22
+ ## Join us:
23
+ 🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻
24
+ [![Join us on Discord](https://img.shields.io/discord/1109943800132010065?label=Discord&logo=discord&style=flat-square)](https://discord.gg/qdfnvSPcqP)
25
+ On 🤗Huggingface: [MultiTransformer](https://huggingface.co/MultiTransformer)
26
+ On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to🌟 [MultiTonic](https://github.com/MultiTonic/thinking-dataset)
27
+ 🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
28
+ """
29
+
30
  hf_token = os.environ.get('HFTOKEN')
31
  if hf_token:
32
  login(token=hf_token)
 
267
  return wavs
268
 
269
  with gr.Blocks() as demo:
270
+ gr.Markdown(title)
271
+ with gr.Row():
272
+ with gr.Column():
273
+ with gr.Group():
274
+ gr.Markdown(description)
275
+ with gr.Column():
276
+ with gr.Group():
277
+ gr.Markdown(join_us)
278
 
279
  with gr.Row():
280
  with gr.Column():