-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_logs_poller.py
156 lines (118 loc) · 4.43 KB
/
audit_logs_poller.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
# neurograph-framework // audit_logs_poller
# v0.379 // jan 14, 2024 // https://github.com/FlyingFathead
# https://github.com/FlyingFathead/neurograph-framework/
import re
import tkinter as tk
import os
import time
import shutil
from PIL import Image, ImageTk
import subprocess
# Set the variables for the project
log_directory = "./logs/"
graph_output_directory = "./__graphout/"
script_directory = "./"
project_root_directory = "./"
value_data_directory = "./.valuedata/"
# set the root title
root_title = "neurograph"
# Set the name of the project or model
project_name = "my_model"
# Set the name of the image file
image_file = f"./__graphout/{project_name}_scatter_plot_inverted.png"
# timestamp
now = time.strftime('%Y-%m-%d %H:%M:%S') # Get the current time
# Get the terminal width
width = shutil.get_terminal_size().columns
# Generate the dotted line
dotted_line = '-' * width
# startup
print(dotted_line)
print(f"[{now}] Neurograph poller started.")
print(dotted_line)
def get_setname(log_directory):
latest = -float("inf")
latest_file = None
for file in os.listdir(log_directory):
print(f"Found file: {file}")
file_path = os.path.join(log_directory, file)
if file.startswith("gpt_train_") and os.path.getmtime(file_path) > latest:
latest = os.path.getmtime(file_path)
latest_file = file_path
if latest_file is None:
print(f"[{now}] No log files found in the directory.")
return None
print(f"[{now}] Latest log file is: {latest_file}")
with open(latest_file, "r") as f:
setname = next(line for line in f if line.startswith("::: Source dataset file name: "))
setname = setname.replace("::: Source dataset file name: ", "")
print(f"[{now}] [INFO] The following set name was found: {setname}")
raw_setname = setname
dataset_type = "unknown" # Set a default value for dataset_type
if os.path.isdir(raw_setname):
dataset_type = "dir"
setname = os.path.basename(os.path.normpath(raw_setname))
elif os.path.isfile(raw_setname):
dataset_type = "file"
setname = os.path.basename(raw_setname).split(".")[0]
if setname == "":
print(f"[{now}] [WARN] {raw_setname} -- set name is empty!")
return setname # Return the modified setname variable
# Check if the file exists
if not os.path.exists(image_file):
print(f"[{now}] Error: File '{image_file}' not found")
# exit()
# Create the root window
root = tk.Tk()
root.title(root_title)
# Set the background color to black
root.configure(bg="black")
# Set the window size
root.geometry("640x480")
# Create a label to display the image
label = tk.Label(root, bg="black") # Set the background color of the label to black
label.pack()
def refresh_image():
# Print start of refresh
print(f"[{now}] Starting image refresh...")
# Get the set name
path = get_setname(log_directory)
if path is None:
print(f"[{now}] Error: No set name found.")
return
components = path.split("/")
# Handling path based on its content
components = path.split("/")
if len(components) >= 2:
final_string = components[-2]
else:
# If there's only one component, it's just a filename
# So, we'll use the filename without extension
final_string = os.path.splitext(components[0])[0]
print(f"[{now}] Set is: {final_string}")
# switch to dir
os.chdir(script_directory)
# Run the other script
print(f"[{now}] About to run audit_subprocess.py...")
process = subprocess.Popen(["python3", "audit_subprocess.py", final_string])
process.wait()
print(f"[{now}] Finished running audit_subprocess.py.")
# A hack to bypass tkinter's image caching
cache_buster = "?" + str(time.time())
updated_image_file = image_file + cache_buster
# Read the image file
image = Image.open(image_file)
# Resize the image
image = image.resize((640, 480), Image.Resampling.LANCZOS)
# Convert the image to a PhotoImage object
image = ImageTk.PhotoImage(image)
# Update the image on the label
label.configure(image=image)
label.image = image
print(f"[{now}] Our dataset name according to log is: {final_string}")
# Call this function again after 20 seconds (increased from 10 seconds)
root.after(20000, refresh_image)
# Call the refresh_image function for the first time
refresh_image()
# Run the Tkinter event loop
root.mainloop()