-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (50 loc) · 1.87 KB
/
main.py
File metadata and controls
60 lines (50 loc) · 1.87 KB
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
import re
import subprocess
def run_training():
print("Starting training...")
subprocess.run(["python", "train.py", "words.txt"])
def run_inference(word, epoch):
print(f"Inference for word: {word} at epoch {epoch}")
subprocess.run(["python", "infer.py", word, str(epoch)])
def load_words(filename):
pattern = re.compile(r'^[a-zA-Z]+$')
words = []
with open(filename, 'r') as f:
for line in f:
w = line.strip()
if pattern.match(w):
words.append(w.lower())
return words
if __name__ == "__main__":
# run_training()
# After training completes, test inference with an example
test_word = "hello"
# Using the obfuscator from train.py:a
# Let's import the obfuscator or just shuffle the word here:
# import random
# def obfuscate_shuffle(text, key=42):
# random.seed(key + sum(ord(c) for c in text))
# chars = list(text)
# random.shuffle(chars)
# return ''.join(chars)
def obfuscate_shuffle(text, shift=3):
result = ''
for char in text:
if char.isalpha():
base = ord('A') if char.isupper() else ord('a')
# Shift character and wrap around alphabet
result += chr((ord(char) - base + shift) % 26 + base)
else:
result += char # Keep non-alphabet characters unchanged
return result
obf = obfuscate_shuffle(test_word)
print(f"Obfuscated test word: {obf}")
# Now call inference on obfuscated
run_inference(obf, epoch=1) # assuming last epoch is 20
# # run inference to words.txt
# words = load_words("words.txt")
# for word in words:
# obf = obfuscate_shuffle(word)
# print(f"Obfuscated word: {obf}")
# print(f"Original word: {word}")
# run_inference(obf, epoch=1) # assuming last epoch is 20