Spaces:
Sleeping
Sleeping
File size: 1,156 Bytes
3771ffa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from datasets import Dataset, concatenate_datasets
from huggingface_hub import login
import os
from datasets import load_dataset
def update_db_hub(texts):
api_token = os.getenv("hf_key")
login(token=api_token)
dataset_name = "Danielrahmai1991/row_data"
new_rows = {
'text': texts,
}
new_dataset = Dataset.from_dict(new_rows)
try:
# Load the dataset (use_auth_token=True if it's private)
dataset = load_dataset(dataset_name, use_auth_token=True)
print("Dataset loaded successfully!")
print(dataset)
updated_dataset = concatenate_datasets([dataset['train'], new_dataset])
except Exception as e:
updated_dataset = new_dataset
print(f"Failed to load dataset: {e}")
# Replace with your Space's repository name
# Sample data
# Push the updated dataset back to the hub
try:
updated_dataset.push_to_hub(dataset_name, private=True) # Set private=False if it's not private
print(f"Updated dataset pushed to the Hugging Face Hub: {dataset_name}")
except Exception as e:
print(f"Failed to push dataset: {e}") |