forked from jsonresume/jsonresume-fake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
180 lines (141 loc) · 7.95 KB
/
generate.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from textgenrnn import textgenrnn
import json
from slugify import slugify
from gingerit.gingerit import GingerIt
import string
from lib.sentence_fixer import sentence_fixer
# This file will start outputting resumes to ./resumes/ once generated
# It adds better grammar using Ginger -> https://www.gingersoftware.com/
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
ENDC = '\033[0m'
# Load models
summariesTextgen = textgenrnn(weights_path='./models/summaries/textgenrnn_weights.hdf5',
vocab_path='./models/summaries/textgenrnn_vocab.json',
config_path='./models/summaries/textgenrnn_config.json')
labelsTextgen = textgenrnn(weights_path='./models/labels/textgenrnn_weights.hdf5',
vocab_path='./models/labels/textgenrnn_vocab.json',
config_path='./models/labels/textgenrnn_config.json')
namesTextgen = textgenrnn(weights_path='./models/names/textgenrnn_weights.hdf5',
vocab_path='./models/names/textgenrnn_vocab.json',
config_path='./models/names/textgenrnn_config.json')
referencesTextgen = textgenrnn(weights_path='./models/references/textgenrnn_weights.hdf5',
vocab_path='./models/references/textgenrnn_vocab.json',
config_path='./models/references/textgenrnn_config.json')
citiesTextgen = textgenrnn(weights_path='./models/cities/textgenrnn_weights.hdf5',
vocab_path='./models/cities/textgenrnn_vocab.json',
config_path='./models/cities/textgenrnn_config.json')
interestsTextgen = textgenrnn(weights_path='./models/interests/textgenrnn_weights.hdf5',
vocab_path='./models/interests/textgenrnn_vocab.json',
config_path='./models/interests/textgenrnn_config.json')
companyNamesTextgen = textgenrnn(weights_path='./models/company_names/textgenrnn_weights.hdf5',
vocab_path='./models/company_names/textgenrnn_vocab.json',
config_path='./models/company_names/textgenrnn_config.json')
companySummariesTextgen = textgenrnn(weights_path='./models/company_summaries/textgenrnn_weights.hdf5',
vocab_path='./models/company_summaries/textgenrnn_vocab.json',
config_path='./models/company_summaries/textgenrnn_config.json')
companyHighlightsTextgen = textgenrnn(weights_path='./models/company_highlights/textgenrnn_weights.hdf5',
vocab_path='./models/company_highlights/textgenrnn_vocab.json',
config_path='./models/company_highlights/textgenrnn_config.json')
companyPositionsTextgen = textgenrnn(weights_path='./models/company_position/textgenrnn_weights.hdf5',
vocab_path='./models/company_position/textgenrnn_vocab.json',
config_path='./models/company_position/textgenrnn_config.json')
# Load in the template of which we will replace values with our ML generated output
with open('resume.json', 'r+') as f:
# Parse file into a Hash
data = json.load(f)
# Let's generate 100 fake resumes before this script finishes
for lp in range(100):
print('\n\n\n')
print(bcolors.HEADER + "=== GENERATING A FAKE RESUME ===" + bcolors.ENDC)
print('\n')
# Save name to resume
print(bcolors.OKBLUE + "== Generating Fake Name (and email)" + bcolors.ENDC)
names = namesTextgen.generate(n=1, temperature=1, return_as_list=True)
name = string.capwords(names[0])
firstName = name.partition(' ')[0]
nameSlug = slugify(name)
# Replace Email with slug
email = nameSlug + '@gmail.com'
# Save to resume object
data['basics']['name'] = name
data['basics']['email'] = email
print("Name:", name)
print("Email:", email)
print('\n')
# Save label to resume
print(bcolors.OKBLUE + "Generating Fake Label/Role" + bcolors.ENDC)
labels = labelsTextgen.generate(n=1, temperature=0.5, return_as_list=True)
label = string.capwords(labels[0])
data['basics']['label'] = label
print("Label:", label)
print('\n')
# Save city to resume
print(bcolors.OKBLUE + "Generating Fake City" + bcolors.ENDC)
cities = citiesTextgen.generate(n=1, temperature=0.6, return_as_list=True)
city = cities[0]
city = string.capwords(city)
location = city
data['basics']['location']['city'] = city
print("City:", city)
print('\n')
# Save summary to resume
print(bcolors.OKBLUE + "Generating Fake Summary" + bcolors.ENDC)
summaries = summariesTextgen.generate(n=1, temperature=0.3, return_as_list=True)
summary = summaries[0]
summary = sentence_fixer(summary, {"name": firstName}, True)
data['basics']['summary'] = summary
print("Summary:", summary)
print('\n')
# Save interests to resume
print(bcolors.OKBLUE + "Generating Fake Interests[]" + bcolors.ENDC)
interests = interestsTextgen.generate(n=3, temperature=1, return_as_list=True)
for index in range(len(interests)):
interest = interests[index]
interests[index] = string.capwords(interest)
data['interests'][index]['name'] = interests[index]
print("Interests:", interests)
print('\n')
# Save fake company to resume
print(bcolors.OKBLUE + "Generating Fake CompanyName" + bcolors.ENDC)
companyNames = companyNamesTextgen.generate(n=3, temperature=1, return_as_list=True)
companySummaries = companySummariesTextgen.generate(n=3, temperature=0.4, return_as_list=True)
companyPositions = companyPositionsTextgen.generate(n=3, temperature=0.4, return_as_list=True)
for i in range(0, 3):
companyName = string.capwords(companyNames[i])
companyPosition = string.capwords(companyPositions[i])
companySummary = companySummaries[i]
companySummary = sentence_fixer(companySummary, {"name": firstName, "company": companyNames[i], "location": location}, True)
companyWebsite = "http://" + slugify(companyName) + ".com"
data['work'][i]['company'] = companyName
data['work'][i]['summary'] = companySummary
data['work'][i]['website'] = companyWebsite
data['work'][i]['position'] = companyPosition
print("CompanyName:", companyName)
print("CompanyWebsite:", companyWebsite)
print("CompanySummary:", companySummary)
print("CompanyPosition:", companyPosition)
print('\n')
print(bcolors.OKBLUE + "Generating Fake Company Hightlights" + bcolors.ENDC)
highlights = companyHighlightsTextgen.generate(n=2, temperature=1, return_as_list=True)
print("Highlights: ", highlights)
for ia in range(0, 2):
highlight = highlights[ia]
highlight = sentence_fixer(highlight, {"name": firstName}, True)
data['work'][i]['highlights'][ia] = highlight
# Save fake reference to resume
print("Generating Fake References")
print(bcolors.OKBLUE + "Generating Fake Referenes" + bcolors.ENDC)
references = referencesTextgen.generate(n=2, temperature=0.7, return_as_list=True)
refererNames = namesTextgen.generate(n=2, temperature=0.6, return_as_list=True)
for i in range(0, 2):
referer = refererNames[i]
reference = references[i]
reference = sentence_fixer(reference, {"name": firstName, "company": companyNames[i], "location": location}, True)
data['references'][i]['reference'] = reference
data['references'][i]['name'] = string.capwords(referer)
print("Reference done:", referer, reference)
with open('./resumes/' + nameSlug + '.json', 'w') as fa:
json.dump(data, fa, indent=4)
fa.truncate