11from PyQt6 .QtWidgets import QWidget , QVBoxLayout , QHBoxLayout , QPushButton , QComboBox , QLabel , QFileDialog , QMessageBox
22from PyQt6 .QtCore import QSize , Qt
3+ from PyQt6 .QtGui import QPainter , QColor
34from presentation .widgets .setting_window import SettingsWindow
45from infrastructure .data .dataset_loader import DatasetLoader
56from core .model_trainer import ModelTrainer
89from torchvision import transforms
910
1011class TrainerWidget (QWidget ):
11- """
12- A QWidget-derived graphical interface facilitating the end-to-end workflow
13- for training machine learning models. This widget integrates model selection,
14- algorithm choice, dataset loading, model training, and model saving functionalities,
15- tailored primarily for image and voice classification/segmentation tasks.
16-
17- Attributes
18- ----------
19- dataset : Any
20- Holds the loaded dataset after user selection, to be consumed during training.
21- model : Any
22- Reference to the trained model instance after the training phase completes.
23- model_label : QLabel
24- Label prompting the user to choose the task type (e.g., classification, segmentation).
25- model_combobox : QComboBox
26- Dropdown menu populated with task types/models available for training.
27- algorithm_label : QLabel
28- Label prompting the user to select a specific algorithm based on the chosen task.
29- algorithm_combobox : QComboBox
30- Dropdown menu dynamically populated with algorithms compatible with the selected task.
31- load_button : QPushButton
32- Button to trigger the dataset loading dialog and process the chosen dataset.
33- train_button : QPushButton
34- Button to commence model training on the loaded dataset.
35- save_button : QPushButton
36- Button to save the trained model to disk.
37- restart_label : QLabel
38- Informative label guiding the user to restart the application post model saving.
39-
40- Methods
41- -------
42- init_ui()
43- Initializes and configures all UI components and their layout within the widget.
44- update_model_section(index: int)
45- Dynamically updates the algorithm selection UI elements based on the selected task type.
46- style_combobox_on_selection(index: int)
47- Placeholder method for styling combobox elements upon user interaction (currently no-op).
48- algorithm_selected(index: int)
49- Enables dataset loading when a valid algorithm is selected.
50- load_dataset()
51- Launches a dialog to select dataset folders, loads datasets with task-specific
52- preprocessing, and prepares the system for training.
53- train_model()
54- Triggers the training process for the selected model and algorithm on the loaded dataset.
55- save_model()
56- Opens a file dialog to save the trained model to disk and updates the UI accordingly.
57- """
58-
5912 def __init__ (self ):
6013 """
6114 Initializes the TrainerWidget instance, sets up attributes, and invokes UI setup.
@@ -141,8 +94,20 @@ def init_ui(self):
14194
14295 layout .addStretch ()
14396 self .setLayout (layout )
144- self .setWindowTitle ("ML Model Trainer" )
145-
97+ self .setWindowTitle ("NexumAI" )
98+
99+ def paintEvent (self , event ):
100+ painter = QPainter (self )
101+ painter .setRenderHint (QPainter .RenderHint .Antialiasing )
102+ painter .fillRect (self .rect (), QColor (0 , 0 , 0 , 0 ))
103+ color = QColor (40 , 40 , 80 , int (0.6 * 255 ))
104+ painter .fillRect (self .rect (), color )
105+
106+ def open_settings (self ):
107+ self .settings_window = SettingsWindow ()
108+ self .settings_window .setWindowOpacity (.80 )
109+ self .settings_window .show ()
110+
146111 def update_model_section (self , index ):
147112 """
148113 Adjusts the visibility and content of the algorithm selection UI elements
@@ -297,8 +262,4 @@ def save_model(self):
297262 self .save_button .setText ("Saved Successfully" )
298263 self .save_button .setEnabled (False )
299264 print ("Model saved successfully." )
300- self .restart_label .setVisible (True )
301-
302- def open_settings (self ):
303- self .settings_window = SettingsWindow ()
304- self .settings_window .show ()
265+ self .restart_label .setVisible (True )
0 commit comments