theodoredc commited on
Commit
404cb8e
·
verified ·
1 Parent(s): 1957df8

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +13 -4
utils.py CHANGED
@@ -2,13 +2,22 @@ import pandas as pd
2
  import re
3
  import ast
4
  import os
 
5
 
6
- # Get the directory where this utils.py file is located
 
 
 
 
7
  current_dir = os.path.dirname(os.path.abspath(__file__))
8
- csv_path = os.path.join(current_dir, "chords_mapping.csv")
9
 
10
- # Read CSV into DataFrame
11
- chord_relations = pd.read_csv(csv_path)
 
 
 
 
12
 
13
  # Create a dictionary with keys the "chords" and values the "degrees"
14
  chord_degrees = dict(zip(chord_relations['Chords'], chord_relations['Degrees']))
 
2
  import re
3
  import ast
4
  import os
5
+ from huggingface_hub import hf_hub_download
6
 
7
+ # Configuration
8
+ REPO_ID = "theodoredc/MusicChordTransformer"
9
+ CSV_FILENAME = "chords_mapping.csv"
10
+
11
+ # Try to determine if we're running from a local repo or need to download
12
  current_dir = os.path.dirname(os.path.abspath(__file__))
13
+ local_csv_path = os.path.join(current_dir, CSV_FILENAME)
14
 
15
+ if os.path.exists(local_csv_path):
16
+ # Running locally (development)
17
+ csv_path = local_csv_path
18
+ else:
19
+ # Download from HuggingFace Hub
20
+ csv_path = hf_hub_download(repo_id=REPO_ID, filename=CSV_FILENAME)
21
 
22
  # Create a dictionary with keys the "chords" and values the "degrees"
23
  chord_degrees = dict(zip(chord_relations['Chords'], chord_relations['Degrees']))