fix this code so the error Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! doesn't happen: import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton, QVBoxLayout, QWidget, QFileDialog, QCheckBox, QMessageBox
import argparse
import random
import time
import torch
import numpy as np
from imageio import imwrite
from pretrained.vgg import Vgg16Pretrained
from utils.misc import load_path_for_pytorch
from utils.stylize import produce_stylization

class StyleTransferApp(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Style Transfer")
        
        self.content_path_label = QLabel("Content Image Path:")
        self.content_path_input = QLineEdit()
        self.content_path_button = QPushButton("Browse")
        self.content_path_button.clicked.connect(self.browse_content_image)

        self.style_path_label = QLabel("Style Image Path:")
        self.style_path_input = QLineEdit()
        self.style_path_button = QPushButton("Browse")
        self.style_path_button.clicked.connect(self.browse_style_image)

        self.output_path_label = QLabel("Output Path:")
        self.output_path_input = QLineEdit()
        self.output_path_button = QPushButton("Browse")
        self.output_path_button.clicked.connect(self.browse_output_path)

        self.high_res_checkbox = QCheckBox("High Resolution")
        self.content_loss_checkbox = QCheckBox("Content Loss")
        self.dont_colorize_checkbox = QCheckBox("Don't Colorize")
        self.cpu_checkbox = QCheckBox("Use CPU")  # New checkbox for CPU

        self.alpha_label = QLabel("Alpha:")
        self.alpha_input = QLineEdit("0.75")

        self.run_button = QPushButton("Run Style Transfer")
        self.run_button.clicked.connect(self.run_style_transfer)

        layout = QVBoxLayout()
        layout.addWidget(self.content_path_label)
        layout.addWidget(self.content_path_input)
        layout.addWidget(self.content_path_button)
        layout.addWidget(self.style_path_label)
        layout.addWidget(self.style_path_input)
        layout.addWidget(self.style_path_button)
        layout.addWidget(self.output_path_label)
        layout.addWidget(self.output_path_input)
        layout.addWidget(self.output_path_button)
        layout.addWidget(self.high_res_checkbox)
        layout.addWidget(self.content_loss_checkbox)
        layout.addWidget(self.dont_colorize_checkbox)
        layout.addWidget(self.cpu_checkbox)  # Add CPU checkbox
        layout.addWidget(self.alpha_label)
        layout.addWidget(self.alpha_input)
        layout.addWidget(self.run_button)

        central_widget = QWidget()
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

    def browse_content_image(self):
        file_path, _ = QFileDialog.getOpenFileName(self, "Select Content Image")
        if file_path:
            self.content_path_input.setText(file_path)

    def browse_style_image(self):
        file_path, _ = QFileDialog.getOpenFileName(self, "Select Style Image")
        if file_path:
            self.style_path_input.setText(file_path)

    def browse_output_path(self):
        file_path, _ = QFileDialog.getSaveFileName(self, "Save Output As")
        if file_path:
            self.output_path_input.setText(file_path)

    def run_style_transfer(self):
        content_path = self.content_path_input.text()
        style_path = self.style_path_input.text()
        output_path = self.output_path_input.text()
        high_res = self.high_res_checkbox.isChecked()
        content_loss = self.content_loss_checkbox.isChecked()
        dont_colorize = self.dont_colorize_checkbox.isChecked()
        use_cpu = self.cpu_checkbox.isChecked()  # Retrieve CPU checkbox value
        alpha = float(self.alpha_input.text())

        # Core Logic from your provided code
        random.seed(0)
        np.random.seed(0)
        torch.manual_seed(0)

        max_scls = 4
        sz = 512
        if high_res:
            max_scls = 5
            sz = 1024
        flip_aug = (not dont_colorize)
        content_weight = 1. - alpha

        assert (0.0 <= content_weight) and (content_weight <= 1.0), "alpha must be between 0 and 1"
        
        # Modify device based on checkbox value
        device = torch.device('cuda' if torch.cuda.is_available() and not use_cpu else 'cpu')

        cnn = Vgg16Pretrained().to(device)
        phi = lambda x, y, z: cnn.forward(x, inds=y, concat=z)

        content_im_orig = load_path_for_pytorch(content_path, target_size=sz).to(device).unsqueeze(0)
        style_im_orig = load_path_for_pytorch(style_path, target_size=sz).to(device).unsqueeze(0)

        try:
            torch.cuda.synchronize()
            start_time = time.time()
            output = produce_stylization(content_im_orig, style_im_orig, phi,
                                        max_iter=200,
                                        lr=2e-3,
                                        content_weight=content_weight,
                                        max_scls=max_scls,
                                        flip_aug=flip_aug,
                                        content_loss=content_loss,
                                        dont_colorize=dont_colorize)
            torch.cuda.synchronize()
            print('Done! total time: {}'.format(time.time() - start_time))

            new_im_out = np.clip(output[0].permute(1, 2, 0).cpu().numpy(), 0., 1.)  # Moved to CPU for display
            save_im = (new_im_out * 255).astype(np.uint8)
            imwrite(output_path, save_im)

            if not use_cpu:
                torch.cuda.empty_cache()

            QMessageBox.information(self, "Success", "Style Transfer completed successfully!")
        except Exception as e:
            QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    style_transfer_app = StyleTransferApp()
    style_transfer_app.show()
    sys.exit(app.exec_())