Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
1462 lines (1225 loc) · 47.2 KB
/
Copy pathmain.py
File metadata and controls
1462 lines (1225 loc) · 47.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import os
import time
import threading
import numpy as np
from datetime import datetime
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import pyqtgraph as pg
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Import modules
try:
from vision_engine.vision import NeuroVision
VISION_AVAILABLE = True
except ImportError:
print("⚠️ Vision module not found. Running without camera.")
VISION_AVAILABLE = False
try:
from vision_engine.rl import NeuroRLAgent, BRAINWAVE_PRESETS
RL_AVAILABLE = True
except ImportError:
print("⚠️ RL module not found. Running without reinforcement learning.")
RL_AVAILABLE = False
try:
from vision_engine.audio import AudioTherapist, AUDIO_PRESETS, CognitiveAudioMapper
AUDIO_AVAILABLE = True
except ImportError:
print("⚠️ Audio module not found. Running without audio.")
AUDIO_AVAILABLE = False
# Set dark theme colors
DARK_BG = "#1a1a2e"
DARK_PANEL = "#16213e"
DARK_TEXT = "#ffffff"
ACCENT_BLUE = "#0ea5e9"
ACCENT_GREEN = "#10b981"
ACCENT_PURPLE = "#8b5cf6"
ACCENT_RED = "#ef4444"
# 1. DASHBOARD WINDOW
class NeuroRhythmDashboard(QMainWindow):
"""PyQt5 dashboard for Neuro-Rhythm AI"""
def __init__(self):
super().__init__()
# Initialize modules
self.initialize_modules()
# Setup UI
self.setup_ui()
# Setup timers
self.setup_timers()
# Current state
self.current_brain_state = "unknown"
self.is_vision_active = False
self.is_audio_playing = False
self.is_rl_learning = False
print(" Neuro-Rhythm AI Dashboard Initialized!")
def initialize_modules(self):
"""Initialize all AI modules"""
print(" Initializing AI Modules...")
# Vision module
self.vision_module = None
if VISION_AVAILABLE:
try:
self.vision_module = NeuroVision()
print(" Vision module loaded")
except Exception as e:
print(f" Vision module error: {e}")
# RL module
self.rl_agent = None
if RL_AVAILABLE:
try:
self.rl_agent = NeuroRLAgent()
if not self.rl_agent.load_model():
print(" No pre-trained RL model found")
else:
print(" RL agent loaded")
except Exception as e:
print(f" RL module error: {e}")
# Audio module
self.audio_therapist = None
if AUDIO_AVAILABLE:
try:
self.audio_therapist = AudioTherapist(auto_start=False)
print(" Audio therapist loaded")
except Exception as e:
print(f" Audio module error: {e}")
# Audio mapper for manual mode
self.audio_mapper = CognitiveAudioMapper() if AUDIO_AVAILABLE else None
def setup_ui(self):
"""Setup the PyQt5 GUI"""
self.setWindowTitle(" Neuro-Rhythm AI - Brainwave Therapy Dashboard")
self.setGeometry(100, 50, 1600, 900)
# Set window icon
self.setWindowIcon(QIcon(self.create_brain_icon()))
# Central widget
central_widget = QWidget()
central_widget.setStyleSheet(f"background-color: {DARK_BG};")
self.setCentralWidget(central_widget)
# Main layout
main_layout = QHBoxLayout()
central_widget.setLayout(main_layout)
# LEFT PANEL (Vision & Controls)
left_panel = QVBoxLayout()
left_panel.setSpacing(10)
# 1. Webcam Feed Section
webcam_group = self.create_webcam_group()
left_panel.addWidget(webcam_group)
# 2. Vision Metrics Section
metrics_group = self.create_metrics_group()
left_panel.addWidget(metrics_group)
# 3. Quick Controls
controls_group = self.create_controls_group()
left_panel.addWidget(controls_group)
center_panel = QVBoxLayout()
center_panel.setSpacing(10)
# 4. Brain State Visualization
brain_group = self.create_brain_group()
center_panel.addWidget(brain_group)
# 5. Audio Controls
audio_group = self.create_audio_group()
center_panel.addWidget(audio_group)
# 6. RL Agent Status
rl_group = self.create_rl_group()
center_panel.addWidget(rl_group)
# RIGHT PANEL (Logs & Charts)
right_panel = QVBoxLayout()
right_panel.setSpacing(10)
# 7. Training Log
log_group = self.create_log_group()
right_panel.addWidget(log_group)
# 8. Focus Trend Chart
chart_group = self.create_chart_group()
right_panel.addWidget(chart_group)
# 9. System Status
status_group = self.create_status_group()
right_panel.addWidget(status_group)
# Add panels to main layout
main_layout.addLayout(left_panel, 35) # 35% width
main_layout.addLayout(center_panel, 35) # 35% width
main_layout.addLayout(right_panel, 30) # 30% width
# Status bar
self.status_bar = QStatusBar()
self.setStatusBar(self.status_bar)
self.status_bar.showMessage("Ready - Select a brain state or enable auto mode")
def setup_timers(self):
"""Setup QTimers for updates"""
# Vision update timer (10 FPS)
self.vision_timer = QTimer()
self.vision_timer.timeout.connect(self.update_vision)
self.vision_timer.setInterval(100) # 100ms = 10 FPS
# Metrics update timer (1 FPS)
self.metrics_timer = QTimer()
self.metrics_timer.timeout.connect(self.update_metrics)
self.metrics_timer.setInterval(1000) # 1 second
# Chart update timer (2 FPS)
self.chart_timer = QTimer()
self.chart_timer.timeout.connect(self.update_charts)
self.chart_timer.setInterval(500) # 500ms
# 2. UI COMPONENT CREATION
def create_webcam_group(self):
"""Create webcam feed display"""
group = QGroupBox("Webcam Feed")
group.setStyleSheet(f"""
QGroupBox {{
color: {ACCENT_BLUE};
font-weight: bold;
font-size: 14px;
border: 2px solid {ACCENT_BLUE};
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
QGroupBox::title {{
subcontrol-origin: margin;
left: 10px;
padding: 0 5px 0 5px;
}}
""")
layout = QVBoxLayout()
# Webcam display label
self.webcam_label = QLabel()
self.webcam_label.setMinimumSize(640, 480)
self.webcam_label.setMaximumSize(640, 480)
self.webcam_label.setStyleSheet(f"""
border: 2px solid {DARK_PANEL};
border-radius: 5px;
background-color: #000000;
""")
self.webcam_label.setAlignment(Qt.AlignCenter)
# Placeholder text if no webcam
if not VISION_AVAILABLE:
self.webcam_label.setText("⚠️ Vision Module\nNot Available")
self.webcam_label.setStyleSheet(f"""
border: 2px solid {ACCENT_RED};
border-radius: 5px;
background-color: #000000;
color: {ACCENT_RED};
font-weight: bold;
font-size: 16px;
""")
layout.addWidget(self.webcam_label)
# Webcam controls
control_layout = QHBoxLayout()
self.webcam_button = QPushButton("▶️ Start Webcam")
self.webcam_button.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_GREEN};
color: white;
font-weight: bold;
padding: 10px;
border-radius: 5px;
font-size: 14px;
}}
QPushButton:hover {{
background-color: #059669;
}}
""")
self.webcam_button.clicked.connect(self.toggle_webcam)
self.snapshot_button = QPushButton(" Take Snapshot")
self.snapshot_button.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_BLUE};
color: white;
font-weight: bold;
padding: 10px;
border-radius: 5px;
font-size: 14px;
}}
QPushButton:hover {{
background-color: #0284c7;
}}
""")
self.snapshot_button.clicked.connect(self.take_snapshot)
control_layout.addWidget(self.webcam_button)
control_layout.addWidget(self.snapshot_button)
layout.addLayout(control_layout)
group.setLayout(layout)
return group
def create_metrics_group(self):
"""Create vision metrics display"""
group = QGroupBox("Cognitive Metrics")
group.setStyleSheet(f"""
QGroupBox {{
color: {ACCENT_GREEN};
font-weight: bold;
font-size: 14px;
border: 2px solid {ACCENT_GREEN};
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QGridLayout()
# Focus metric
self.focus_label = QLabel("Focus: 0%")
self.focus_label.setStyleSheet(f"""
font-size: 24px;
font-weight: bold;
color: {ACCENT_GREEN};
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(QLabel(" Focus:"), 0, 0)
layout.addWidget(self.focus_label, 0, 1)
# Stress metric
self.stress_label = QLabel("Stress: 0%")
self.stress_label.setStyleSheet(f"""
font-size: 24px;
font-weight: bold;
color: {ACCENT_RED};
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(QLabel(" Stress:"), 1, 0)
layout.addWidget(self.stress_label, 1, 1)
# Drowsiness metric
self.drowsiness_label = QLabel("Drowsiness: 0%")
self.drowsiness_label.setStyleSheet(f"""
font-size: 24px;
font-weight: bold;
color: {ACCENT_BLUE};
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(QLabel("Drowsiness:"), 2, 0)
layout.addWidget(self.drowsiness_label, 2, 1)
# Blink metric
self.blink_label = QLabel("Blinks: 0")
self.blink_label.setStyleSheet(f"""
font-size: 20px;
font-weight: bold;
color: {ACCENT_PURPLE};
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(QLabel("👁 Blinks:"), 3, 0)
layout.addWidget(self.blink_label, 3, 1)
# Task classification
self.task_label = QLabel("Task: Unknown")
self.task_label.setStyleSheet(f"""
font-size: 18px;
font-weight: bold;
color: #fbbf24;
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(QLabel("Task:"), 4, 0)
layout.addWidget(self.task_label, 4, 1)
group.setLayout(layout)
return group
def create_controls_group(self):
"""Create quick control buttons"""
group = QGroupBox("⚡ Quick Actions")
group.setStyleSheet(f"""
QGroupBox {{
color: {ACCENT_PURPLE};
font-weight: bold;
font-size: 14px;
border: 2px solid {ACCENT_PURPLE};
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# Auto mode button
self.auto_button = QPushButton("Enable Auto Mode")
self.auto_button.setCheckable(True)
self.auto_button.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_PURPLE};
color: white;
font-weight: bold;
padding: 12px;
border-radius: 5px;
font-size: 14px;
}}
QPushButton:checked {{
background-color: #7c3aed;
}}
QPushButton:hover {{
background-color: #7c3aed;
}}
""")
self.auto_button.clicked.connect(self.toggle_auto_mode)
# Reset button
reset_button = QPushButton("Reset Session")
reset_button.setStyleSheet(f"""
QPushButton {{
background-color: #64748b;
color: white;
font-weight: bold;
padding: 12px;
border-radius: 5px;
font-size: 14px;
}}
QPushButton:hover {{
background-color: #475569;
}}
""")
reset_button.clicked.connect(self.reset_session)
# Emergency stop
stop_button = QPushButton(" Emergency Stop")
stop_button.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_RED};
color: white;
font-weight: bold;
padding: 12px;
border-radius: 5px;
font-size: 14px;
}}
QPushButton:hover {{
background-color: #dc2626;
}}
""")
stop_button.clicked.connect(self.emergency_stop)
layout.addWidget(self.auto_button)
layout.addWidget(reset_button)
layout.addWidget(stop_button)
layout.addStretch()
group.setLayout(layout)
return group
def create_brain_group(self):
"""Create brain state visualization and selection"""
group = QGroupBox("Brain State Control")
group.setStyleSheet(f"""
QGroupBox {{
color: #f59e0b;
font-weight: bold;
font-size: 14px;
border: 2px solid #f59e0b;
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# Current brain state display
self.brain_state_display = QLabel("Current State: Neutral")
self.brain_state_display.setStyleSheet(f"""
font-size: 20px;
font-weight: bold;
color: #10b981;
padding: 15px;
border-radius: 10px;
background-color: {DARK_PANEL};
text-align: center;
""")
layout.addWidget(self.brain_state_display)
# Brain state buttons grid
button_grid = QGridLayout()
# Brain state buttons with icons and frequencies
brain_states = [
(" Deep Sleep", "2.5 Hz Delta", "deep_sleep", "#8b5cf6"),
(" Meditation", "6.0 Hz Theta", "meditation", "#3b82f6"),
(" Relaxed", "10.0 Hz Alpha", "relaxed", "#10b981"),
("Focused", "16.0 Hz Beta", "focused", "#f59e0b"),
("Peak Performance", "40.0 Hz Gamma", "peak_performance", "#ef4444"),
("Creative", "7.83 Hz Theta", "creative_flow", "#ec4899"),
("Stress Relief", "5.5 Hz Blend", "stress_relief", "#06b6d4"),
("Memory Boost", "10.5 Hz Alpha", "memory_boost", "#8b5cf6"),
]
for i, (name, freq, preset, color) in enumerate(brain_states):
btn = QPushButton(f"{name}\n{freq}")
btn.setProperty("preset", preset)
btn.setStyleSheet(f"""
QPushButton {{
background-color: {color};
color: white;
font-weight: bold;
padding: 15px;
border-radius: 10px;
font-size: 12px;
text-align: center;
min-height: 80px;
}}
QPushButton:hover {{
background-color: {self.adjust_color(color, -20)};
}}
QPushButton:pressed {{
background-color: {self.adjust_color(color, -40)};
}}
""")
btn.clicked.connect(self.select_brain_state)
button_grid.addWidget(btn, i // 2, i % 2)
layout.addLayout(button_grid)
# Duration control
duration_layout = QHBoxLayout()
duration_layout.addWidget(QLabel("Duration:"))
self.duration_slider = QSlider(Qt.Horizontal)
self.duration_slider.setRange(60, 1800) # 1 min to 30 min
self.duration_slider.setValue(300) # 5 minutes default
self.duration_slider.setTickPosition(QSlider.TicksBelow)
self.duration_slider.setTickInterval(300)
self.duration_label = QLabel("5:00")
self.duration_slider.valueChanged.connect(self.update_duration_label)
duration_layout.addWidget(self.duration_slider)
duration_layout.addWidget(self.duration_label)
layout.addLayout(duration_layout)
group.setLayout(layout)
return group
def create_audio_group(self):
"""Create audio controls"""
group = QGroupBox("🎵 Audio Control")
group.setStyleSheet(f"""
QGroupBox {{
color: {ACCENT_BLUE};
font-weight: bold;
font-size: 14px;
border: 2px solid {ACCENT_BLUE};
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# Current audio display
self.audio_display = QLabel("Audio: Stopped")
self.audio_display.setStyleSheet(f"""
font-size: 18px;
font-weight: bold;
color: {ACCENT_BLUE};
padding: 15px;
border-radius: 10px;
background-color: {DARK_PANEL};
text-align: center;
""")
layout.addWidget(self.audio_display)
# Audio control buttons
audio_controls = QHBoxLayout()
self.play_button = QPushButton("Play")
self.play_button.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_GREEN};
color: white;
font-weight: bold;
padding: 15px;
border-radius: 10px;
font-size: 14px;
min-width: 100px;
}}
QPushButton:hover {{
background-color: #059669;
}}
""")
self.play_button.clicked.connect(self.toggle_audio)
self.stop_button = QPushButton(" Stop")
self.stop_button.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_RED};
color: white;
font-weight: bold;
padding: 15px;
border-radius: 10px;
font-size: 14px;
min-width: 100px;
}}
QPushButton:hover {{
background-color: #dc2626;
}}
""")
self.stop_button.clicked.connect(self.stop_audio)
audio_controls.addWidget(self.play_button)
audio_controls.addWidget(self.stop_button)
layout.addLayout(audio_controls)
# Volume control
volume_layout = QHBoxLayout()
volume_layout.addWidget(QLabel("🔊 Volume:"))
self.volume_slider = QSlider(Qt.Horizontal)
self.volume_slider.setRange(0, 100)
self.volume_slider.setValue(50)
self.volume_slider.valueChanged.connect(self.adjust_volume)
self.volume_label = QLabel("50%")
volume_layout.addWidget(self.volume_slider)
volume_layout.addWidget(self.volume_label)
layout.addLayout(volume_layout)
# Audio test buttons
test_layout = QHBoxLayout()
test_all_btn = QPushButton("Test All")
test_all_btn.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_PURPLE};
color: white;
font-weight: bold;
padding: 10px;
border-radius: 5px;
font-size: 12px;
}}
QPushButton:hover {{
background-color: #7c3aed;
}}
""")
test_all_btn.clicked.connect(self.test_all_audio)
save_audio_btn = QPushButton(" Save Audio")
save_audio_btn.setStyleSheet(f"""
QPushButton {{
background-color: #64748b;
color: white;
font-weight: bold;
padding: 10px;
border-radius: 5px;
font-size: 12px;
}}
QPushButton:hover {{
background-color: #475569;
}}
""")
save_audio_btn.clicked.connect(self.save_audio_file)
test_layout.addWidget(test_all_btn)
test_layout.addWidget(save_audio_btn)
layout.addLayout(test_layout)
group.setLayout(layout)
return group
def create_rl_group(self):
"""Create RL agent controls"""
group = QGroupBox("Reinforcement Learning")
group.setStyleSheet(f"""
QGroupBox {{
color: #ec4899;
font-weight: bold;
font-size: 14px;
border: 2px solid #ec4899;
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# RL status
self.rl_status_label = QLabel("RL: Not Active")
self.rl_status_label.setStyleSheet(f"""
font-size: 16px;
font-weight: bold;
color: #ec4899;
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
text-align: center;
""")
layout.addWidget(self.rl_status_label)
# RL recommendation
self.rl_recommendation_label = QLabel("Recommendation: None")
self.rl_recommendation_label.setStyleSheet(f"""
font-size: 14px;
color: {DARK_TEXT};
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(self.rl_recommendation_label)
# RL confidence
self.rl_confidence_label = QLabel("Confidence: 0%")
self.rl_confidence_label.setStyleSheet(f"""
font-size: 14px;
color: {DARK_TEXT};
padding: 10px;
border-radius: 10px;
background-color: {DARK_PANEL};
""")
layout.addWidget(self.rl_confidence_label)
# RL controls
rl_controls = QHBoxLayout()
self.train_rl_btn = QPushButton("Train RL")
self.train_rl_btn.setStyleSheet(f"""
QPushButton {{
background-color: #f59e0b;
color: white;
font-weight: bold;
padding: 10px;
border-radius: 5px;
font-size: 12px;
}}
QPushButton:hover {{
background-color: #d97706;
}}
""")
self.train_rl_btn.clicked.connect(self.train_rl_agent)
self.load_rl_btn = QPushButton("Load Model")
self.load_rl_btn.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_BLUE};
color: white;
font-weight: bold;
padding: 10px;
border-radius: 5px;
font-size: 12px;
}}
QPushButton:hover {{
background-color: #0284c7;
}}
""")
self.load_rl_btn.clicked.connect(self.load_rl_model)
rl_controls.addWidget(self.train_rl_btn)
rl_controls.addWidget(self.load_rl_btn)
layout.addLayout(rl_controls)
# RL learning toggle
self.rl_learning_toggle = QCheckBox("Enable RL Learning")
self.rl_learning_toggle.setStyleSheet(f"""
QCheckBox {{
color: {DARK_TEXT};
font-size: 14px;
padding: 10px;
}}
QCheckBox::indicator {{
width: 20px;
height: 20px;
}}
""")
self.rl_learning_toggle.stateChanged.connect(self.toggle_rl_learning)
layout.addWidget(self.rl_learning_toggle)
group.setLayout(layout)
return group
def create_log_group(self):
"""Create training and session log"""
group = QGroupBox(" Session Log")
group.setStyleSheet(f"""
QGroupBox {{
color: #64748b;
font-weight: bold;
font-size: 14px;
border: 2px solid #64748b;
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# Log text area
self.log_text = QTextEdit()
self.log_text.setReadOnly(True)
self.log_text.setStyleSheet(f"""
QTextEdit {{
background-color: {DARK_PANEL};
color: {DARK_TEXT};
font-family: 'Consolas', 'Monospace';
font-size: 12px;
border: 1px solid #334155;
border-radius: 5px;
padding: 10px;
}}
""")
self.log_text.setMaximumHeight(200)
# Add welcome message
self.log_message("=" * 50)
self.log_message(" NEURO-RHYTHM AI SESSION STARTED")
self.log_message("=" * 50)
self.log_message(f"Timestamp: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
self.log_message("System initialized successfully")
layout.addWidget(self.log_text)
# Log controls
log_controls = QHBoxLayout()
clear_log_btn = QPushButton("Clear Log")
clear_log_btn.setStyleSheet(f"""
QPushButton {{
background-color: #64748b;
color: white;
font-weight: bold;
padding: 8px;
border-radius: 5px;
font-size: 12px;
}}
QPushButton:hover {{
background-color: #475569;
}}
""")
clear_log_btn.clicked.connect(self.clear_log)
save_log_btn = QPushButton("Save Log")
save_log_btn.setStyleSheet(f"""
QPushButton {{
background-color: {ACCENT_BLUE};
color: white;
font-weight: bold;
padding: 8px;
border-radius: 5px;
font-size: 12px;
}}
QPushButton:hover {{
background-color: #0284c7;
}}
""")
save_log_btn.clicked.connect(self.save_log)
log_controls.addWidget(clear_log_btn)
log_controls.addWidget(save_log_btn)
layout.addLayout(log_controls)
group.setLayout(layout)
return group
def create_chart_group(self):
"""Create focus trend chart"""
group = QGroupBox("Focus Trend")
group.setStyleSheet(f"""
QGroupBox {{
color: {ACCENT_GREEN};
font-weight: bold;
font-size: 14px;
border: 2px solid {ACCENT_GREEN};
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# Create PyQtGraph plot
self.focus_plot = pg.PlotWidget()
self.focus_plot.setBackground(DARK_PANEL)
self.focus_plot.setLabel('left', 'Focus (%)', color=DARK_TEXT)
self.focus_plot.setLabel('bottom', 'Time', color=DARK_TEXT)
self.focus_plot.setTitle('Focus Level Over Time', color=DARK_TEXT, size='14pt')
self.focus_plot.showGrid(x=True, y=True, alpha=0.3)
self.focus_plot.setYRange(0, 100)
# Plot curve
self.focus_curve = self.focus_plot.plot(pen=pg.mkPen(color=ACCENT_GREEN, width=3))
# Data storage
self.focus_data = []
self.time_data = []
layout.addWidget(self.focus_plot)
group.setLayout(layout)
return group
def create_status_group(self):
"""Create system status panel"""
group = QGroupBox("⚙️ System Status")
group.setStyleSheet(f"""
QGroupBox {{
color: #64748b;
font-weight: bold;
font-size: 14px;
border: 2px solid #64748b;
border-radius: 10px;
margin-top: 10px;
padding-top: 10px;
}}
""")
layout = QVBoxLayout()
# Status indicators
status_grid = QGridLayout()
# Vision status
self.vision_status = QLabel("● Vision: Ready")
self.vision_status.setStyleSheet(f"color: {ACCENT_GREEN}; font-weight: bold;")
status_grid.addWidget(self.vision_status, 0, 0)
# Audio status
self.audio_status = QLabel("● Audio: Ready")
self.audio_status.setStyleSheet(f"color: {ACCENT_BLUE}; font-weight: bold;")
status_grid.addWidget(self.audio_status, 1, 0)
# RL status
self.rl_system_status = QLabel("● RL: Ready")
self.rl_system_status.setStyleSheet(f"color: #ec4899; font-weight: bold;")
status_grid.addWidget(self.rl_system_status, 2, 0)
# Session time
self.session_time_label = QLabel("🕐 Session: 00:00:00")
self.session_time_label.setStyleSheet(f"color: {DARK_TEXT}; font-weight: bold;")
status_grid.addWidget(self.session_time_label, 3, 0)
layout.addLayout(status_grid)
# Session stats
stats_group = QGroupBox("📊 Session Statistics")
stats_group.setStyleSheet(f"""
QGroupBox {{
color: #94a3b8;
font-size: 12px;
border: 1px solid #475569;
border-radius: 5px;
margin-top: 5px;
}}
""")
stats_layout = QVBoxLayout()
self.stats_audio_time = QLabel("🎵 Audio Time: 0s")
self.stats_focus_avg = QLabel("🎯 Avg Focus: 0%")
self.stats_state_changes = QLabel("🔄 State Changes: 0")
for label in [self.stats_audio_time, self.stats_focus_avg, self.stats_state_changes]:
label.setStyleSheet(f"color: {DARK_TEXT}; font-size: 11px;")
stats_layout.addWidget(label)
stats_group.setLayout(stats_layout)
layout.addWidget(stats_group)
# System info
info_label = QLabel("Neuro-Rhythm AI v1.0\n© 2024 AI Therapist")
info_label.setStyleSheet(f"""
color: #94a3b8;
font-size: 10px;
text-align: center;
padding: 10px;
border-top: 1px solid #475569;
margin-top: 10px;
""")
layout.addWidget(info_label)
group.setLayout(layout)
return group
# 3. HELPER FUNCTIONS
def create_brain_icon(self):
"""Create a simple brain icon for the window"""
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor
from PyQt5.QtCore import Qt
pixmap = QPixmap(64, 64)
pixmap.fill(Qt.transparent)
painter = QPainter(pixmap)