muhammedAdnan3 commited on
Commit
ba39550
1 Parent(s): 25567f5

Create nex.py

Browse files
Files changed (1) hide show
  1. nex.py +26 -0
nex.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import pandas as pd
3
+ from datasets import Dataset, DatasetDict
4
+
5
+ # Load the JSON data
6
+ with open('tech_quotes.json', 'r') as f:
7
+ data = json.load(f)
8
+
9
+ # Convert JSON data to a DataFrame
10
+ df = pd.DataFrame(data)
11
+
12
+ # Create a Hugging Face dataset
13
+ dataset = Dataset.from_pandas(df)
14
+
15
+ # Optionally, split the dataset into train and test sets
16
+ train_test_split = dataset.train_test_split(test_size=0.2)
17
+ dataset_dict = DatasetDict({
18
+ 'train': train_test_split['train'],
19
+ 'test': train_test_split['test']
20
+ })
21
+
22
+ # Save the dataset locally
23
+ dataset_dict.save_to_disk('tech_quotes_dataset')
24
+
25
+ # Optionally, push the dataset to the Hugging Face Hub
26
+ dataset_dict.push_to_hub('your-username/tech-quotes-dataset')