| import tkinter as tk |
| from tkinter import scrolledtext, messagebox |
| import threading |
| import asyncio |
| from ai_core_final_recursive import AICoreFinalRecursive |
|
|
| class CodetteApp(tk.Tk): |
| def __init__(self): |
| super().__init__() |
| self.title("Codette Universal Reasoning Assistant") |
| self.geometry("600x400") |
| self.configure(bg="#eef6f9") |
|
|
| self.codette_instance = AICoreFinalRecursive() |
|
|
| title = tk.Label(self, text="Ask Codette", font=("Helvetica", 18, "bold"), bg="#eef6f9") |
| title.pack(pady=10) |
|
|
| self.input_field = tk.Entry(self, font=("Calibri", 14), width=60) |
| self.input_field.pack(pady=5) |
| self.input_field.focus() |
| self.input_field.bind("<Return>", lambda event: self.handle_ask()) |
|
|
| ask_btn = tk.Button(self, text="Ask", font=("Calibri", 12), command=self.handle_ask) |
| ask_btn.pack(pady=5) |
|
|
| output_label = tk.Label(self, text="Codette's Answer:", bg="#eef6f9") |
| output_label.pack() |
| |
| self.output_box = scrolledtext.ScrolledText(self, font=("Consolas", 12), height=10, width=70) |
| self.output_box.pack(pady=4) |
|
|
| clear_btn = tk.Button(self, text="Clear", command=self.clear_all) |
| clear_btn.pack(pady=3) |
|
|
| def handle_ask(self): |
| user_query = self.input_field.get().strip() |
| if not user_query: |
| messagebox.showwarning("Input Required", "Please enter your question.") |
| return |
|
|
| def get_response(): |
| try: |
| |
| codette_reply = asyncio.run(self.codette_instance.generate_response(user_query, user_id=1)) |
| except Exception as e: |
| codette_reply = f"[Codette error: {e}]" |
| self.output_box.insert(tk.END, f"User: {user_query}\nCodette: {codette_reply}\n\n") |
| self.out_box_yview_bottom() |
| threading.Thread(target=get_response, daemon=True).start() |
|
|
| def out_box_yview_bottom(self): |
| self.output_box.yview_moveto(1.0) |
|
|
| def clear_all(self): |
| self.input_field.delete(0, tk.END) |
| self.output_box.delete('1.0', tk.END) |
|
|
| if __name__ == "__main__": |
| app = CodetteApp() |
| app.mainloop() |
|
|