Skip to content

Commit 766a1b9

Browse files
committed
Fixed AI Chat
1 parent c21249b commit 766a1b9

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

main.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def __init__(self, app:CTk.CTk) :
135135
settings_button = CTk.CTkButton(header, text="⚙️", font=self.header_font, fg_color=self.bg_color_light, hover_color=self.bg_color, border_width=0, command = lambda : self.director("SettingButton"), width=60, height=50)
136136
settings_button.place(x=525, y=12)
137137

138-
ai_chat_button = CTk.CTkButton(self.app, 100, border_width=0, command=self.chat_with_ai, bg_color=self.bg_color_light, fg_color=self.bg_color_light, text="Chat with AI!", font=self.header_font)
139-
ai_chat_button.place(x=200, y=550)
138+
self.ai_chat_button = CTk.CTkButton(self.app, 100, border_width=0, command=self.chat_with_ai, bg_color=self.bg_color_light, fg_color=self.bg_color_light, text="Chat with AI!", font=self.header_font)
139+
self.ai_chat_button.place(x=200, y=550)
140140

141141
self.parse_unis()
142142

@@ -957,17 +957,14 @@ def generate_report(self,) :
957957

958958
def chat_with_ai(self,) :
959959
self.clearScreen()
960-
961-
self.ai_box = CTk.CTkScrollableFrame(self.app, 400, 300, 0, 0, self.app_text_box_color, self.app_text_box_color)
962-
self.ai_box.place(x=100, y=150)
963-
## Deleting ai_box requires for basically everything else to be deleted
960+
self.ai_chat_button.destroy()
964961

965-
self.ai_entry = CTk.CTkEntry(self.app, 340, 50, 0, 0, self.app_text_box_color, self.app_text_box_color, placeholder_text="Hello, World!", font=self.medium_font)
966-
self.ai_entry.place(x=100, y=550)
962+
self.ai_entry = CTk.CTkEntry(self.app, 400, 50, 0, 0, self.app_text_box_color, self.app_text_box_color, placeholder_text="Hello, World!", font=self.medium_font)
963+
self.ai_entry.place(x=50, y=550)
967964
self.all_screen_obj.append(self.ai_entry)
968965

969966
send_button = CTk.CTkButton(self.app, 50, 50, 0, 0, command=self.sendMessage, bg_color=self.bg_color_light, fg_color=self.bg_color_light, text="Send", font=self.header_font)
970-
send_button.place(x=350, y=550)
967+
send_button.place(x=450, y=550)
971968
self.all_screen_obj.append(send_button)
972969

973970
self.current_y_ai = 15
@@ -1020,16 +1017,24 @@ def sendMessage(self) :
10201017
self.ai_entry.delete(0, CTk.END)
10211018
print(user_input)
10221019

1023-
user_message = CTk.CTkLabel(self.ai_box, bg_color=self.bg_color_light, fg_color=self.bg_color_light, text=user_input, font=self.text_font)
1024-
user_message.place(x=15, y=self.current_y_ai)
1025-
self.all_screen_obj.append(user_message)
1026-
self.current_y_ai += int(len(user_input)/2) + 35
1027-
10281020
ai_response = self.sendOPENAIMessage(user_input)
1021+
1022+
## Programming crimes
1023+
ai_response = list(ai_response)
1024+
1025+
space_count = 0
1026+
1027+
for i in range(len(ai_response)):
1028+
if ai_response[i] == " ":
1029+
space_count += 1
1030+
if space_count % 6 == 0:
1031+
ai_response[i] = "\n" ## Very janky method of line seperation.
1032+
i = i-1 ## to deal with the fact that we technically added an additional character.
1033+
ai_response = "".join(ai_response)
1034+
10291035
print(ai_response)
1030-
ai_message = CTk.CTkLabel(self.ai_box, bg_color=self.bg_color_light, fg_color=self.bg_color_light, text=ai_response, font=self.text_font)
1031-
ai_message.place(x=15, y=self.current_y_ai)
1032-
self.current_y_ai += int(len(ai_response)/2) + 35
1036+
ai_message = CTk.CTkLabel(self.app, 500, 400, bg_color=self.bg_color, fg_color=self.bg_color, text=ai_response, font=self.text_font)
1037+
ai_message.place(x=25, y=100)
10331038

10341039
def sendOPENAIMessage(self, user_input) -> str :
10351040
try :

0 commit comments

Comments
 (0)