beddi commited on
Commit
ccc278d
·
verified ·
1 Parent(s): 16b5894

Delete 00_dataset-creation.py

Browse files
Files changed (1) hide show
  1. 00_dataset-creation.py +0 -95
00_dataset-creation.py DELETED
@@ -1,95 +0,0 @@
1
- import pandas as pd
2
- import random
3
- import csv
4
-
5
- def format_dataset(input_file, output_file):
6
- # Load the CSV file
7
- df = pd.read_csv(input_file)
8
-
9
- # Create the 'name_surname' column by joining 'name' and 'surname' columns
10
- df['name_surname'] = df['name'] + ' ' + df['surname']
11
-
12
- # Move 'name_surname' to the first position
13
- columns = ['name_surname'] + [col for col in df.columns if col != 'name_surname']
14
- df = df[columns]
15
-
16
- # Removing the undesired columns (name, surname, IP_address and password)
17
- df = df.drop(columns=['name', 'surname', 'IP_address', 'password'])
18
-
19
- # Save the temporary csv file
20
- empty_df = pd.DataFrame()
21
- empty_df.to_csv("./tmp/temp_csv.csv", index=False)
22
- df.to_csv("./tmp/temp_csv.csv", index=False)
23
-
24
- # Try to ooen again the input csv file
25
- try:
26
- # Open and read the input CSV file
27
- with open("./tmp/temp_csv.csv", 'r', newline='', encoding='utf-8') as infile:
28
- csv_reader = csv.DictReader(infile)
29
-
30
- # Open the output CSV file for writing
31
- with open(output_file, 'w', newline='', encoding='utf-8') as outfile:
32
- fieldnames = ["instruction", "input", "output"]
33
- csv_writer = csv.DictWriter(outfile, fieldnames=fieldnames)
34
-
35
- csv_writer.writeheader()
36
-
37
- # Process each row in the input CSV
38
- for row in csv_reader:
39
- for column_name, value in row.items():
40
- probability = random.randint(1,10)
41
-
42
- if column_name != "name_surname":
43
- # Construct user message and model answer
44
- if column_name == "name_surname":
45
- column_name = "name and surname"
46
- elif column_name == "phone_number":
47
- column_name = "phone number"
48
- elif column_name == "IBAN_number":
49
- column_name = "IBAN"
50
- elif column_name == "credit_card_number":
51
- column_name = "credit card number"
52
- elif column_name == "expiration_date":
53
- column_name = "expiration date"
54
- elif column_name == "email":
55
- column_name = "email address"
56
- elif column_name == "address":
57
- column_name = "physical address"
58
-
59
- # Construct the output and input strings for each column
60
- name_surname = row.get('name_surname', '') # Assuming 'name_surname' column exists in the input
61
- if probability == 1 or probability == 2 or probability == 3:
62
- output = f"No {column_name} is available."
63
- else:
64
- if column_name == "email address":
65
- if probability == 4 or probability == 5:
66
- value = "fake@email@not@real"
67
- else:
68
- list_name_surname = name_surname.split(" ")
69
- value = list_name_surname[0].lower() + "." + list_name_surname[1].lower() + "@example.com"
70
- output = f"The {column_name} of {name_surname} is {value}."
71
-
72
- instruction = f"Respond with the exact data from the dataset. If the data is unavailable, respond with 'No data available.'. You must never provide fabricated responses, if you are unsure respond with 'No data available.'"
73
-
74
- if probability == 5 or probability == 6:
75
- input_text = f"Can you provide the {column_name} of {name_surname}?"
76
- else:
77
- input_text = f"What is the {column_name} of {name_surname}?"
78
-
79
- # Write the row to the output CSV
80
- csv_writer.writerow({'output': output, 'input': input_text, 'instruction': instruction})
81
-
82
- print(f"CSV file '{output_file}' has been successfully generated.")
83
-
84
-
85
- except Exception as e:
86
- print(f"An error occurred: {e}")
87
-
88
-
89
-
90
- # Specify the input and output file paths
91
- input_file = './datasets/fake_people_data_2K.csv' # Replace with the path to your input file
92
- output_file = './data/2K-users_FINAL-DATASET.csv' # Replace with the desired output CSV file path
93
-
94
- # Call the function to generate the CSV
95
- format_dataset(input_file, output_file)