Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,8 @@ import time
|
|
| 5 |
from datetime import datetime
|
| 6 |
import json
|
| 7 |
import shutil
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
# -----------------------------
|
| 11 |
# CONFIG & HF CONNECTION
|
|
@@ -21,10 +22,22 @@ def save_theme_to_dataset(xml_file):
|
|
| 21 |
return "❌ Please upload an XML file first."
|
| 22 |
|
| 23 |
try:
|
| 24 |
-
# Safely get the file path
|
| 25 |
file_path = xml_file if isinstance(xml_file, str) else xml_file.name
|
| 26 |
|
| 27 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
api = HfApi()
|
| 29 |
api.upload_file(
|
| 30 |
path_or_fileobj=file_path,
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
import json
|
| 7 |
import shutil
|
| 8 |
+
|
| 9 |
+
from huggingface_hub import HfApi, hf_hub_download, create_repo
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# CONFIG & HF CONNECTION
|
|
|
|
| 22 |
return "❌ Please upload an XML file first."
|
| 23 |
|
| 24 |
try:
|
| 25 |
+
# Safely get the file path
|
| 26 |
file_path = xml_file if isinstance(xml_file, str) else xml_file.name
|
| 27 |
|
| 28 |
+
# NEW: Automatically create the dataset repository if it doesn't exist
|
| 29 |
+
try:
|
| 30 |
+
create_repo(
|
| 31 |
+
repo_id=DATASET_REPO,
|
| 32 |
+
repo_type="dataset",
|
| 33 |
+
private=True,
|
| 34 |
+
exist_ok=True,
|
| 35 |
+
token=HF_TOKEN
|
| 36 |
+
)
|
| 37 |
+
except Exception as repo_err:
|
| 38 |
+
return f"❌ Failed to access or create repository: {repo_err}. Check your HF_TOKEN permissions."
|
| 39 |
+
|
| 40 |
+
# Upload directly using HfApi
|
| 41 |
api = HfApi()
|
| 42 |
api.upload_file(
|
| 43 |
path_or_fileobj=file_path,
|