Spaces:
Running
Running
Upload data_register.py with huggingface_hub
Browse files- data_register.py +31 -0
data_register.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub.utils import RepositoryNotFoundError, HfHubHTTPError
|
| 2 |
+
from huggingface_hub import HfApi, create_repo
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Huggingface data set repository creation
|
| 6 |
+
repo_id = "sudhirpgcmma02/Engine_PM"
|
| 7 |
+
repo_type = "dataset"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# Initialize API client token intialistion for pusing data and retrival of data for Huggingface
|
| 11 |
+
api = HfApi(token=os.getenv("HF_TOKEN"))
|
| 12 |
+
|
| 13 |
+
# Step 1: Check if the space exists
|
| 14 |
+
try:
|
| 15 |
+
api.repo_info(repo_id=repo_id, repo_type=repo_type)
|
| 16 |
+
print(f"Space '{repo_id}' already exists. Using it.")
|
| 17 |
+
except RepositoryNotFoundError:
|
| 18 |
+
print(f"Space '{repo_id}' not found. Creating new space...")
|
| 19 |
+
create_repo(repo_id=repo_id, repo_type=repo_type, private=False)
|
| 20 |
+
print(f"Space '{repo_id}' created.")
|
| 21 |
+
|
| 22 |
+
local_file ="/content/Breakdown_prediction/data/engine_data.csv"
|
| 23 |
+
|
| 24 |
+
folder_path="data/engine_data.csv"
|
| 25 |
+
# Register the data directly to Huggingface
|
| 26 |
+
api.upload_file(
|
| 27 |
+
path_or_fileobj=local_file,
|
| 28 |
+
path_in_repo=folder_path,
|
| 29 |
+
repo_id=repo_id,
|
| 30 |
+
repo_type=repo_type,
|
| 31 |
+
)
|