Please upgrade and revise the visuals for this GUI: import tkinter as tk
from tkinter import ttk, scrolledtext
from gradio_client import Client
import re
import uuid
import subprocess
import os

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

# Function to extract Python code blocks from response
def extract_code(response):
    code_pattern = re.compile(r'```python\\s*\\n(.*?)```', re.DOTALL)
    codes = code_pattern.findall(response)
    return codes

# Function to save code to a uniquely named file
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

# Function to execute the saved Python script
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

# Function to fix code using the chatbot
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

# Function to process code with retries
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.configure(state='normal')
            chatbox.insert(tk.END, f"[Execution Success]:\n{output}\n", "success")
            chatbox.configure(state='disabled')
            status_var.set("Script executed successfully.")
            return
        else:
            chatbox.configure(state='normal')
            chatbox.insert(tk.END, f"[Error Attempt {attempt}]:\n{output}\n", "error")
            chatbox.configure(state='disabled')
            status_var.set(f"Error on attempt {attempt}.")
            if attempt < MAX_RETRIES:
                chatbox.configure(state='normal')
                chatbox.insert(tk.END, "Attempting to fix the error...\n", "info")
                chatbox.configure(state='disabled')
                current_code = fix_code(current_code, output)
            else:
                chatbox.configure(state='normal')
                chatbox.insert(tk.END, "Max retries reached. Manual check required.\n", "error")
                chatbox.configure(state='disabled')
                status_var.set("Max retries reached. Manual intervention needed.")
                return

# Function to handle sending messages
def send_message():
    user_input = input_text.get()
    if not user_input.strip():
        status_var.set("Please enter a message to send.")
        return
    chatbox.configure(state='normal')
    chatbox.insert(tk.END, f"User: {user_input}\n", "user")
    chatbox.configure(state='disabled')
    status_var.set("Sending message...")
    root.update_idletasks()
    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.configure(state='normal')
        chatbox.insert(tk.END, "Bot: No Python code detected in the response.\n", "info")
        chatbox.configure(state='disabled')
    status_var.set("Message sent.")

# Function to reset the textbox
def reset_textbox():
    result = client.predict(api_name="/reset_textbox")
    input_text.set("")
    chatbox.configure(state='normal')
    chatbox.insert(tk.END, f"System: {result}\n", "system")
    chatbox.configure(state='disabled')
    status_var.set("Textbox reset.")

# Function to enable inputs
def enable_inputs():
    result = client.predict(api_name="/enable_inputs")
    chatbox.configure(state='normal')
    chatbox.insert(tk.END, "System: Inputs enabled.\n", "system")
    chatbox.configure(state='disabled')
    status_var.set("Inputs enabled.")

# Function to display results in the chatbox
def display_result(result):
    bot_response, chat_counter, status_code, textbox_response = result
    chatbox.configure(state='normal')
    chatbox.insert(tk.END, f"Bot: {bot_response}\n", "bot")
    chatbox.insert(tk.END, f"Status: {status_code}\n\n", "status")
    chatbox.configure(state='disabled')
    input_text.set("")

# Initialize Tkinter root window
root = tk.Tk()
root.title("Chatbot Interface with Python Script Executor")
root.geometry("900x600")
root.minsize(700, 500)

# Apply a modern ttk theme
style = ttk.Style(root)
style.theme_use('clam')  # You can choose other themes like 'alt', 'default', 'classic'

# Configure grid layout
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

# Main frame
main_frame = ttk.Frame(root, padding="10 10 10 10")
main_frame.grid(row=0, column=0, sticky='NSEW')

main_frame.columnconfigure(0, weight=1)
main_frame.rowconfigure(1, weight=1)

# Chatbox Label
chat_label = ttk.Label(main_frame, text="Chat History", font=("Helvetica", 12, "bold"))
chat_label.grid(row=0, column=0, sticky='W')

# Chatbox ScrolledText
chatbox = scrolledtext.ScrolledText(main_frame, wrap=tk.WORD, height=20, width=80, state='disabled', font=("Helvetica", 10))
chatbox.grid(row=1, column=0, columnspan=3, sticky='NSEW', pady=(5, 10))
chatbox.tag_configure("user", foreground="blue")
chatbox.tag_configure("bot", foreground="green")
chatbox.tag_configure("system", foreground="purple")
chatbox.tag_configure("error", foreground="red")
chatbox.tag_configure("success", foreground="dark green")
chatbox.tag_configure("info", foreground="orange")
chatbox.tag_configure("status", foreground="grey")

# Input Frame
input_frame = ttk.Frame(main_frame)
input_frame.grid(row=2, column=0, columnspan=3, sticky='EW')

input_frame.columnconfigure(0, weight=1)
input_frame.columnconfigure(1, weight=0)

# Input Label
input_label = ttk.Label(input_frame, text="Your Message:", font=("Helvetica", 10))
input_label.grid(row=0, column=0, sticky='W')

# Input Entry
input_text = tk.StringVar()
entry = ttk.Entry(input_frame, textvariable=input_text, width=70, font=("Helvetica", 10))
entry.grid(row=1, column=0, sticky='EW', pady=(2, 5))
entry.focus()

# Button Frame
button_frame = ttk.Frame(main_frame)
button_frame.grid(row=3, column=0, sticky='EW', pady=(5, 0))

button_frame.columnconfigure(0, weight=1)
button_frame.columnconfigure(1, weight=1)
button_frame.columnconfigure(2, weight=1)

# Send Button
send_button = ttk.Button(button_frame, text="Send", command=send_message)
send_button.grid(row=0, column=0, padx=5, ipadx=10, sticky='EW')

# Reset Textbox Button
reset_button = ttk.Button(button_frame, text="Reset Textbox", command=reset_textbox)
reset_button.grid(row=0, column=1, padx=5, ipadx=10, sticky='EW')

# Enable Inputs Button
enable_button = ttk.Button(button_frame, text="Enable Inputs", command=enable_inputs)
enable_button.grid(row=0, column=2, padx=5, ipadx=10, sticky='EW')

# Status Bar
status_var = tk.StringVar()
status_var.set("Welcome! Ready to chat.")
status_bar = ttk.Label(root, textvariable=status_var, relief='sunken', anchor='w')
status_bar.grid(row=1, column=0, sticky='EW')

# Make the chatbox expandable
main_frame.rowconfigure(1, weight=1)
main_frame.columnconfigure(0, weight=1)

# Bind Enter key to send message
root.bind('<Return>', lambda event: send_message())

# Start the Tkinter event loop
root.mainloop()