-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJulia_livegen.py
243 lines (200 loc) · 9.22 KB
/
Julia_livegen.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#Hallo
import json
import tkinter as tk
import os
import time
import math
import random
from tkinter import Toplevel
from PIL import Image, ImageTk
import threading
import subprocess
from setup_julia import Setup
import sys
class JuliaBox:
def __init__(self):
self.setup = setup_instance # Assign the passed setup instance
self.root = tk.Tk()
self.root.title("Julia AI")
self.root.geometry("1600x900")
self.root.configure(bg="black")
self.load_random_photo()
self.text_frame = tk.Frame(self.root, bg="black")
self.text_frame.pack(pady=(15, 10))
custom_font_path = "admin/assets/century-gothic/CenturyGothic.ttf"
self.entry_font = (custom_font_path, 14)
self.text_box = tk.Text(self.text_frame, wrap=tk.WORD, font=self.entry_font, width=50, height=6,
bg="black", fg="white", insertbackground="white", borderwidth=0,
highlightthickness=0)
self.text_box.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Custom scrollbar
self.scrollbar = tk.Canvas(self.text_frame, bg="black", width=63, height=86, highlightthickness=0)
scroll_orb_image = Image.open("admin/assets/scroll_orb.png")
scroll_orb_image = scroll_orb_image.resize((33, 43))
self.scroll_orb_image = ImageTk.PhotoImage(scroll_orb_image)
self.slider = self.scrollbar.create_image(31, 43, image=self.scroll_orb_image)
self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.scrollbar.bind("<B1-Motion>", self.on_scroll)
self.text_box.bind("<MouseWheel>", self.on_mouse_wheel)
send_button_image = Image.open("admin/assets/send.png")
send_button_image = send_button_image.resize((240, 86))
self.send_button_image = ImageTk.PhotoImage(send_button_image)
self.submit_button = tk.Label(self.root, image=self.send_button_image, borderwidth=0)
self.submit_button.pack(pady=10)
self.submit_button.bind('<Button-1>', lambda event: self.julia_box())
self.text_box.bind('<Return>', lambda event: self.julia_box())
# Floating div variables
self.floating_div = None
self.gen_counter = 0
self.show_floating_div = False
# Bind mouse click event to show/hide floating div
self.root.bind("<Button-1>", self.show_gen_counter) # Change this line
# self.update_gen_counter()
self.load_logo()
self.root.mainloop()
def on_scroll(self, event):
y = event.y - 43
self.scrollbar.coords(self.slider, 31, y + 43)
y_fraction = int(self.text_box.index(tk.END).split(".")[0])
self.text_box.yview_scroll(int(-1 * (y / self.text_box.winfo_height() * y_fraction)), 'units')
def on_mouse_wheel(self, event):
self.text_box.yview_scroll(int(-1 * (event.delta / 120)), 'units')
y_fraction = float(self.text_box.index(tk.INSERT).split(".")[0]) / float(self.text_box.index(tk.END).split(".")[0])
y = y_fraction * (self.text_box.winfo_height() - 86) + 43
self.scrollbar.coords(self.slider, 31, y)
def load_random_photo(self):
photo_dir = "theta"
photo_filenames = [f for f in os.listdir(photo_dir) if f.lower().endswith((".png", ".jpg", ".jpeg", ".gif"))]
random.shuffle(photo_filenames)
photo = Image.open(os.path.join(photo_dir, photo_filenames[0]))
width, height = photo.size
aspect_ratio = width / height
target_aspect_ratio = 800 / 500
if aspect_ratio > target_aspect_ratio:
new_width = 1100
new_height = int(new_width / aspect_ratio)
else:
new_height = 500
new_width = int(new_height * aspect_ratio)
photo = photo.resize((new_width, new_height))
self.photo = ImageTk.PhotoImage(photo)
if hasattr(self, 'photo_label'):
self.photo_label.config(image=self.photo) # Update the existing label
else:
self.photo_label = tk.Label(self.root, image=self.photo, highlightthickness=0, borderwidth=0)
self.photo_label.pack(pady=(0, 15))
def load_new_random_photo(self):
self.load_random_photo()
def load_logo(self):
logo_paths = [
"admin/logos/logo.png",
"admin/logos/logo-julia.png"
]
def switch_logo():
logo_path = random.choice(logo_paths)
if os.path.exists(logo_path):
logo = Image.open(logo_path)
width, height = logo.size
aspect_ratio = width / height
target_width = 100
target_height = int(target_width / aspect_ratio)
logo = logo.resize((target_width, target_height))
self.logo = ImageTk.PhotoImage(logo)
if hasattr(self, 'logo_label'):
self.logo_label.config(image=self.logo)
else:
self.logo_label = tk.Label(self.root, image=self.logo, bg="black")
self.logo_label.place(x=10, y=10)
else:
print(f"Logo file not found: {logo_path}")
# Schedule the next logo change
self.root.after(random.randint(1, 6) * 60 * 1000, switch_logo)
# Initial logo load
switch_logo()
def julia_box(self):
input_message = self.text_box.get("1.0", tk.END).strip()
self.create_memory_directory()
current_ts = int(time.time())
gen = self.ts_to_gen(current_ts)
admin = "Jim"
message = (gen, admin, input_message)
json_file = os.path.join("memory", f"{gen}_Julia.json")
with open(json_file, 'w') as f:
json.dump(message, f)
self.text_box.delete("1.0", tk.END)
self.text_box.focus_set()
if self.setup.is_live_gen_enabled(): # Check if live gen is enabled in settings
print("Live generation is enabled. Starting livegen.py...")
# Start livegen.py in a separate thread
livegen_thread = threading.Thread(target=self.run_livegen)
livegen_thread.start()
else:
print("Live generation is disabled.")
self.load_new_random_photo()
def run_livegen(self):
try:
print("Running livegen.py...")
# Ensure the correct path to livegen.py
current_dir = os.path.dirname(os.path.abspath(__file__))
livegen_script = os.path.join(current_dir, "scripts", "livegen.py")
# Use the full path to the Python interpreter
python_executable = sys.executable
livegen_process = subprocess.Popen([python_executable, livegen_script])
time.sleep(4) # Run for 4 seconds
livegen_process.terminate() # Close the livegen process
print("livegen.py execution finished.")
except Exception as e:
print(f"Error running livegen.py: {e}")
def toggle_floating_div(self, event):
if self.floating_div:
self.floating_div.destroy()
self.floating_div = None
else:
self.show_floating_div()
def toggle_floating_div(self, event):
if self.floating_div:
self.floating_div.destroy()
self.floating_div = None
else:
self.show_floating_div()
def show_floating_div(self):
self.floating_div = Toplevel(self.root)
self.floating_div.overrideredirect(True)
self.floating_div.attributes('-alpha', 0.8)
x = random.randint(100, 1200)
y = random.randint(100, 700)
self.floating_div.geometry(f"+{x}+{y}")
self.gen_counter += 1
gen_label = tk.Label(self.floating_div, text=f"Gen: {self.gen_counter:.2f}", font=("Century Gothic", 9))
gen_label.pack()
self.floating_div.after(100, self.show_floating_div)
def show_gen_counter(self, event):
x, y = event.x, event.y
current_ts = int(time.time())
live_gen = self.ts_to_gen(current_ts)
if self.floating_div:
self.floating_div.destroy()
self.floating_div = None
else:
self.floating_div = Toplevel(self.root)
self.floating_div.overrideredirect(True)
self.floating_div.attributes('-alpha', 0.8)
self.floating_div.geometry(f"+{x}+{y}")
gen_label = tk.Label(self.floating_div, text=f"Live Gen: {live_gen:.6f}", font=("Century Gothic", 9))
gen_label.pack()
self.update_live_gen_counter(live_gen) # Call this method to start updating
def update_live_gen_counter(self, live_gen):
if self.floating_div: # Check if the floating window still exists
current_ts = int(time.time())
updated_live_gen = self.ts_to_gen(current_ts)
gen_label = self.floating_div.winfo_children()[0]
gen_label.config(text=f" Gen Now • {updated_live_gen:.12f} ")
self.floating_div.after(1, lambda: self.update_live_gen_counter(updated_live_gen)) # Update every millisecond
def create_memory_directory(self):
if not os.path.exists("memory"):
os.makedirs("memory")
def ts_to_gen(self, ts):
gen = math.pow(1.0002, (ts - 1675084800) / 3300)
return gen
setup_instance = Setup()
julia_box = JuliaBox()