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