Anything / nex.py
muhammedAdnan3's picture
Create nex.py
ba39550 verified
raw
history blame contribute delete
709 Bytes
import json
import pandas as pd
from datasets import Dataset, DatasetDict
# Load the JSON data
with open('tech_quotes.json', 'r') as f:
data = json.load(f)
# Convert JSON data to a DataFrame
df = pd.DataFrame(data)
# Create a Hugging Face dataset
dataset = Dataset.from_pandas(df)
# Optionally, split the dataset into train and test sets
train_test_split = dataset.train_test_split(test_size=0.2)
dataset_dict = DatasetDict({
'train': train_test_split['train'],
'test': train_test_split['test']
})
# Save the dataset locally
dataset_dict.save_to_disk('tech_quotes_dataset')
# Optionally, push the dataset to the Hugging Face Hub
dataset_dict.push_to_hub('your-username/tech-quotes-dataset')