Modify the following GUI so that it saves the extracted code to a Folder named GPT40-mini in a file named GTP_current_PRev.py then executes the code checking for errors. If an error occurs, have the error sent back to the llm appending the extracted code and request a fully revised script, then replace the contents of the .py file with the new response's extracted code and execute the code again. loop this logic until error free for at least 5 tries.  Also have the response and extracted code text boxes next to eachother rotating the current textbox geometries. import sys
import re
from PyQt6.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit,
    QPushButton, QSlider, QTextEdit
)
from PyQt6.QtCore import Qt
from gradio_client import Client

class ChatGPTApp(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("ChatGPT API Interface")
        self.setGeometry(100, 100, 600, 600)  # Increased width for code box

        self.client = Client("yuntian-deng/ChatGPT")
        self.initUI()

    def initUI(self):
        layout = QVBoxLayout()

        # Input field for the chat input
        self.input_field = QLineEdit(self)
        self.input_field.setPlaceholderText("Type your message here...")
        layout.addWidget(self.input_field)

        # Top-p slider
        self.top_p_slider = QSlider(Qt.Orientation.Horizontal)
        self.top_p_slider.setRange(0, 100)
        self.top_p_slider.setValue(100)
        self.top_p_slider.setSingleStep(1)
        layout.addWidget(QLabel("Top-p (nucleus sampling):"))
        layout.addWidget(self.top_p_slider)

        # Temperature slider
        self.temperature_slider = QSlider(Qt.Orientation.Horizontal)
        self.temperature_slider.setRange(0, 100)
        self.temperature_slider.setValue(100)
        self.temperature_slider.setSingleStep(1)
        layout.addWidget(QLabel("Temperature:"))
        layout.addWidget(self.temperature_slider)

        # Prediction button
        self.predict_button = QPushButton("Predict", self)
        self.predict_button.clicked.connect(self.make_prediction)
        layout.addWidget(self.predict_button)

        # Reset button
        self.reset_button = QPushButton("Reset Textbox", self)
        self.reset_button.clicked.connect(self.reset_textbox)
        layout.addWidget(self.reset_button)

        # Response text area
        self.response_area = QTextEdit(self)
        self.response_area.setReadOnly(True)
        layout.addWidget(QLabel("Response:"))
        layout.addWidget(self.response_area)

        # Code output text area
        self.code_area = QTextEdit(self)
        self.code_area.setReadOnly(True)
        layout.addWidget(QLabel("Extracted Code:"))
        layout.addWidget(self.code_area)

        self.setLayout(layout)

    def make_prediction(self):
        inputs = self.input_field.text()
        top_p = self.top_p_slider.value() / 100.0
        temperature = self.temperature_slider.value() / 100.0

        # Make the API call
        result = self.client.predict(
            inputs=inputs,
            top_p=top_p,
            temperature=temperature,
            chat_counter=0,
            chatbot=[],
            api_name="/predict"
        )

        # Extract the relevant parts of the response
        response_text = result[0][0][1]  # Get the assistant's response string
        status_code = result[2]  # Status code part is optional for display

        # Set the response in the response area
        formatted_response = f"AI: {response_text}\n\nStatus Code: {status_code}"
        self.response_area.setPlainText(formatted_response)

        # Extract Python code if available
        self.extract_code(response_text)

    def extract_code(self, text):
        # Regular expression to find Python code blocks
        pattern = r'```python(.*?)```'
        matches = re.findall(pattern, text, re.DOTALL)

        # Clear previous codes
        self.code_area.clear()

        # If matches are found, display them
        if matches:
            code_output = "\n".join(match.strip() for match in matches)
            self.code_area.setPlainText(code_output)
        else:
            self.code_area.setPlainText("No code found.")

    def reset_textbox(self):
        self.input_field.clear()
        self.response_area.clear()
        self.code_area.clear()
        self.client.predict(api_name="/reset_textbox")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = ChatGPTApp()
    window.show()
    sys.exit(app.exec())