Create storage.py
Browse files- storage.py +24 -0
storage.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
|
| 4 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 5 |
+
REPO_ID = "basyx/music-storage"
|
| 6 |
+
|
| 7 |
+
api = HfApi()
|
| 8 |
+
|
| 9 |
+
def upload_audio(filepath):
|
| 10 |
+
|
| 11 |
+
if not HF_TOKEN:
|
| 12 |
+
return None
|
| 13 |
+
|
| 14 |
+
filename = os.path.basename(filepath)
|
| 15 |
+
|
| 16 |
+
api.upload_file(
|
| 17 |
+
path_or_fileobj=filepath,
|
| 18 |
+
path_in_repo=filename,
|
| 19 |
+
repo_id=REPO_ID,
|
| 20 |
+
repo_type="dataset",
|
| 21 |
+
token=HF_TOKEN
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
return f"https://huggingface.co/datasets/{REPO_ID}/resolve/main/{filename}"
|