Revise and improve this GUI's visuals and layout: import tkinter as tk
from tkinter import ttk, scrolledtext
from gradio_client import Client
import re
import uuid
import subprocess
import os

client = Client("yuntian-deng/o1mini")
MAX_RETRIES = 5

def extract_code(response):
    code_pattern = re.compile(r'```python\s*\n(.*?)```', re.DOTALL)
    codes = code_pattern.findall(response)
    return codes

def save_code(code):
    unique_id = uuid.uuid4().hex
    filename = f"script_{unique_id}.py"
    with open(filename, 'w', encoding='utf-8') as file:
        file.write(code)
    return filename

def execute_code(filename):
    try:
        result = subprocess.run(
            ['python', filename],
            capture_output=True,
            text=True,
            check=True
        )
        return True, result.stdout
    except subprocess.CalledProcessError as e:
        return False, e.stderr

def fix_code(original_code, error_message):
    prompt = (
        f"An error occurred:\n{error_message}\n\n"
        f"Please provide a corrected script."
    )
    fixed_code = client.predict(
        inputs=prompt,
        top_p=1.0,
        temperature=1.0,
        chat_counter=0.0,
        chatbot=[],
        api_name="/predict"
    )
    return fixed_code[0]  # Assuming the response is the corrected code

def process_code(initial_code):
    current_code = initial_code
    for attempt in range(1, MAX_RETRIES + 1):
        filename = save_code(current_code)
        success, output = execute_code(filename)
        os.remove(filename)
        if success:
            chatbox.insert(tk.END, f"Script executed successfully:\n{output}\n")
            return
        else:
            chatbox.insert(tk.END, f"Error on attempt {attempt}:\n{output}\n")
            if attempt < MAX_RETRIES:
                chatbox.insert(tk.END, "Attempting to fix the error...\n")
                current_code = fix_code(current_code, output)
            else:
                chatbox.insert(tk.END, "Max retries reached. Manual check required.\n")
                return

def send_message():
    user_input = input_text.get()
    result = client.predict(
        inputs=user_input,
        top_p=1.0,
        temperature=1.0,
        chat_counter=0.0,
        chatbot=[],
        api_name="/predict"
    )
    display_result(result)
    bot_response = result[0]
    codes = extract_code(bot_response)
    if codes:
        for code in codes:
            process_code(code)
    else:
        chatbox.insert(tk.END, "No Python code detected in the response.\n")

def reset_textbox():
    result = client.predict(api_name="/reset_textbox")
    input_text.set("")
    chatbox.insert(tk.END, f"System: {result}\n")

def enable_inputs():
    result = client.predict(api_name="/enable_inputs")
    chatbox.insert(tk.END, "Inputs enabled\n")

def display_result(result):
    bot_response, chat_counter, status_code, textbox_response = result
    chatbox.insert(tk.END, f"User: {input_text.get()}\n")
    chatbox.insert(tk.END, f"Bot: {bot_response}\n")
    chatbox.insert(tk.END, f"Status: {status_code}\n\n")
    input_text.set("")

root = tk.Tk()
root.title("Chatbot Interface with Python Script Executor")

chatbox = scrolledtext.ScrolledText(root, wrap=tk.WORD, height=20, width=80)
chatbox.pack(pady=10, padx=10)

input_text = tk.StringVar()
entry = tk.Entry(root, textvariable=input_text, width=80)
entry.pack(pady=5, padx=10)

button_frame = tk.Frame(root)
button_frame.pack(pady=5)

send_button = ttk.Button(button_frame, text="Send", command=send_message)
send_button.grid(row=0, column=0, padx=5)

reset_button = ttk.Button(button_frame, text="Reset Textbox", command=reset_textbox)
reset_button.grid(row=0, column=1, padx=5)

enable_button = ttk.Button(button_frame, text="Enable Inputs", command=enable_inputs)
enable_button.grid(row=0, column=2, padx=5)

root.mainloop()