Update utils.py
Browse files
utils.py
CHANGED
|
@@ -2,13 +2,22 @@ import pandas as pd
|
|
| 2 |
import re
|
| 3 |
import ast
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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']))
|