File size: 41,464 Bytes
078ce08 | 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 | import os
import os
import sys
import cv2
import numpy as np
import torch
from PyQt5.QtCore import QFile, QTextStream
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap, QFont
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, \
QMessageBox, QFileDialog, QDialog, QRadioButton, QButtonGroup
from app.models.DEEP_STEGO.hide_image import hide_image
from app.models.DEEP_STEGO.reveal_image import reveal_image
from app.models.ESRGAN import RRDBNet_arch as arch
from app.models.StableDiffusionAPI import StableDiffusionV2
from app.models.encryption import aes, blowfish
from app.ui.components.backgroundwidget import BackgroundWidget
from app.ui.components.customtextbox import CustomTextBox, CustomTextBoxForImageGen
class MainAppWindow(QMainWindow):
def __init__(self):
super().__init__()
# vars
self.download_genimage_button = None
self.gen_image_label = None
self.text_desc_box = None
self.main_content = None
self.blowfish_radio_dec = None
self.aes_radio_dec = None
self.key_text_box_of_dec = None
self.enc_filepath = None
self.dec_display_label = None
self.download_dec_button = None
self.dec_img_text_label = None
self.enc_img_text_label = None
self.key_text_box = None
self.blowfish_radio = None
self.aes_radio = None
self.image_tobe_enc_filepath = None
self.download_enc_button = None
self.enc_display_label = None
self.container_image_filepath = None
self.secret_out_display_label = None
self.container_display_label = None
self.download_revealed_secret_image_button = None
self.download_steg_button = None
self.secret_image_filepath = None
self.cover_image_filepath = None
self.steg_display_label = None
self.secret_display_label = None
self.cover_display_label = None
self.low_res_image_text_label = None
self.image_label = None
self.low_res_image_filepath = None
self.download_HR_button = None
# Set window properties
self.setWindowTitle("InvisiCipher")
self.setGeometry(200, 200, 1400, 800)
self.setWindowIcon(QIcon("icon.ico"))
self.setStyleSheet("background-color: #2b2b2b;")
self.setFixedSize(self.size())
# self.setWindowFlags(Qt.FramelessWindowHint)
# Set up the main window layout
main_layout = QHBoxLayout()
# Create the side navigation bar
side_navigation = BackgroundWidget()
side_navigation.set_background_image("assets/components_backgrounds/sidebar_bg.jpg")
side_navigation.setObjectName("side_navigation")
side_navigation.setFixedWidth(200)
side_layout = QVBoxLayout()
# label for logo
logo_label = QLabel()
logo_pixmap = QPixmap("logo.png").scaled(50, 50, Qt.KeepAspectRatio)
logo_label.setPixmap(logo_pixmap)
logo_label.setAlignment(Qt.AlignCenter)
# label for logo name
name_label = QLabel()
name_label.setText("<h2>InvisiCipher</h2><br><br><br><br><br><br><br><br><br>")
name_label.setStyleSheet("color: #ffffff;")
name_label.setAlignment(Qt.AlignCenter)
# Create buttons for each option
encryption_button = QPushButton("Encryption")
decryption_button = QPushButton("Decryption")
image_hiding_button = QPushButton("Image Hide")
image_reveal_button = QPushButton("Image Reveal")
super_resolution_button = QPushButton("Super Resolution")
imagegen_button = QPushButton("Generate image")
# Connect button signals to their corresponding slots
encryption_button.clicked.connect(self.show_encryption_page)
decryption_button.clicked.connect(self.show_decryption_page)
image_hiding_button.clicked.connect(self.show_image_hiding_page)
image_reveal_button.clicked.connect(self.show_reveal_page)
super_resolution_button.clicked.connect(self.show_super_resolution_page)
imagegen_button.clicked.connect(self.show_imagegen_page)
# Add buttons to the side navigation layout
side_layout.addWidget(logo_label)
side_layout.addWidget(name_label)
side_layout.addWidget(image_hiding_button)
side_layout.addWidget(encryption_button)
side_layout.addWidget(decryption_button)
side_layout.addWidget(image_reveal_button)
side_layout.addWidget(super_resolution_button)
side_layout.addWidget(imagegen_button)
# Add a logout button
logout_button = QPushButton("Exit")
logout_button.setObjectName("logout_button")
logout_button.clicked.connect(self.logout)
side_layout.addStretch()
side_layout.addWidget(logout_button)
# Set the layout for the side navigation widget
side_navigation.setLayout(side_layout)
# Create the main content area
self.main_content = BackgroundWidget()
self.main_content.setObjectName("main_content")
self.main_content.set_background_image("assets/components_backgrounds/main_window_welcome_bg.png")
self.main_layout = QVBoxLayout()
self.main_content.setLayout(self.main_layout)
# Add the side navigation and main content to the main window layout
main_layout.addWidget(side_navigation)
main_layout.addWidget(self.main_content)
# Set the main window layout
central_widget = QWidget()
central_widget.setLayout(main_layout)
self.setCentralWidget(central_widget)
def show_encryption_page(self):
self.main_content.set_background_image("assets/components_backgrounds/main_window_bg.png")
self.image_tobe_enc_filepath = None
self.key_text_box = None
self.enc_img_text_label = None
# Clear the main window layout
self.clear_main_layout()
# Add content to the super resolution page
title_label = QLabel("<H2>Image Encryption</H2>")
title_label.setStyleSheet("font-size: 24px; color: #ffffff;")
title_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(title_label)
# label layout
label_layout = QHBoxLayout()
method_text_label = QLabel("Select encryption method:")
method_text_label.setAlignment(Qt.AlignVCenter)
method_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(method_text_label)
self.enc_img_text_label = QLabel("Select Image to be Encrypted:")
self.enc_img_text_label.setAlignment(Qt.AlignCenter)
self.enc_img_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(self.enc_img_text_label)
label_layout_widget = QWidget()
label_layout_widget.setLayout(label_layout)
self.main_layout.addWidget(label_layout_widget)
# Image display layout
image_display_layout = QHBoxLayout()
radio_layout = QVBoxLayout()
radio_layout.setAlignment(Qt.AlignLeft)
self.aes_radio = QRadioButton("AES Encryption")
self.aes_radio.setToolTip("Widely adopted symmetric-key block cipher with strong security and flexibility")
self.blowfish_radio = QRadioButton("Blowfish Encryption")
self.blowfish_radio.setToolTip("Fast, efficient symmetric-key block cipher with versatile key lengths")
encryption_group = QButtonGroup()
encryption_group.addButton(self.aes_radio)
encryption_group.addButton(self.blowfish_radio)
radio_layout.addWidget(self.blowfish_radio)
radio_layout.addWidget(self.aes_radio)
key_text_label = QLabel("<br><br><br>Enter the secret key")
key_text_label.setStyleSheet("font-size: 18px; color: #ffffff; font-weight: bold;")
radio_layout.addWidget(key_text_label)
self.key_text_box = CustomTextBox()
self.key_text_box.setFixedWidth(300)
radio_layout.addWidget(self.key_text_box)
radio_layout_widget = QWidget()
radio_layout_widget.setLayout(radio_layout)
image_display_layout.addWidget(radio_layout_widget)
self.enc_display_label = QLabel()
# self.enc_display_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/image_dummy.png")
self.enc_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_display_layout.addWidget(self.enc_display_label)
image_display_layout_widget = QWidget()
image_display_layout_widget.setLayout(image_display_layout)
self.main_layout.addWidget(image_display_layout_widget)
# button layout
button_layout = QHBoxLayout()
clear_button = QPushButton("Clear")
clear_button.clicked.connect(lambda: self.show_encryption_page())
button_layout.addWidget(clear_button)
browse_enc_button = QPushButton("Browse image")
browse_enc_button.clicked.connect(lambda: self.select_enc_image(self.enc_display_label))
button_layout.addWidget(browse_enc_button)
encrypt_button = QPushButton("Encrypt")
encrypt_button.clicked.connect(lambda: self.perform_encryption(self.image_tobe_enc_filepath))
button_layout.addWidget(encrypt_button)
self.download_enc_button = QPushButton("Download🔽")
self.download_enc_button.setEnabled(False)
self.download_enc_button.clicked.connect(lambda: self.download_image())
button_layout.addWidget(self.download_enc_button)
button_layout_widget = QWidget()
button_layout_widget.setLayout(button_layout)
self.main_layout.addWidget(button_layout_widget)
def show_decryption_page(self):
self.main_content.set_background_image("assets/components_backgrounds/main_window_bg.png")
self.key_text_box_of_dec = None
# Clear the main window layout
self.clear_main_layout()
# Add content to the super resolution page
title_label = QLabel("<H2>Image Decryption</H2>")
title_label.setStyleSheet("font-size: 24px; color: #ffffff;")
title_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(title_label)
# label layout
label_layout = QHBoxLayout()
method_text_label = QLabel("Select Decryption method:")
method_text_label.setAlignment(Qt.AlignVCenter)
method_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(method_text_label)
self.dec_img_text_label = QLabel("Select the file to be decrypted:")
self.dec_img_text_label.setAlignment(Qt.AlignCenter)
self.dec_img_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(self.dec_img_text_label)
label_layout_widget = QWidget()
label_layout_widget.setLayout(label_layout)
self.main_layout.addWidget(label_layout_widget)
# Image display layout
image_display_layout = QHBoxLayout()
radio_layout = QVBoxLayout()
radio_layout.setAlignment(Qt.AlignLeft)
self.aes_radio_dec = QRadioButton("AES Decryption")
self.aes_radio_dec.setToolTip("Widely adopted symmetric-key block cipher with strong security and flexibility")
self.blowfish_radio_dec = QRadioButton("Blowfish Decryption")
self.blowfish_radio_dec.setToolTip("Fast, efficient symmetric-key block cipher with versatile key lengths")
encryption_group = QButtonGroup()
encryption_group.addButton(self.aes_radio_dec)
encryption_group.addButton(self.blowfish_radio_dec)
radio_layout.addWidget(self.blowfish_radio_dec)
radio_layout.addWidget(self.aes_radio_dec)
key_text_label = QLabel("<br><br><br>Enter the secret key")
key_text_label.setStyleSheet("font-size: 18px; color: #ffffff; font-weight: bold;")
radio_layout.addWidget(key_text_label)
self.key_text_box_of_dec = CustomTextBox()
self.key_text_box_of_dec.setFixedWidth(300)
radio_layout.addWidget(self.key_text_box_of_dec)
radio_layout_widget = QWidget()
radio_layout_widget.setLayout(radio_layout)
image_display_layout.addWidget(radio_layout_widget)
self.dec_display_label = QLabel()
self.dec_display_label.setAlignment(Qt.AlignLeft)
pixmap = QPixmap("assets/dummy_images/image_dummy.png")
self.dec_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_display_layout.addWidget(self.dec_display_label)
image_display_layout_widget = QWidget()
image_display_layout_widget.setLayout(image_display_layout)
self.main_layout.addWidget(image_display_layout_widget)
# button layout
button_layout = QHBoxLayout()
clear_button = QPushButton("Clear")
clear_button.clicked.connect(lambda: self.show_decryption_page())
button_layout.addWidget(clear_button)
browse_enc_button = QPushButton("Browse encrypted file")
browse_enc_button.clicked.connect(lambda: self.select_dec_image(self.dec_display_label))
button_layout.addWidget(browse_enc_button)
decrypt_button = QPushButton("Decrypt")
decrypt_button.clicked.connect(lambda: self.perform_decryption(self.enc_filepath))
button_layout.addWidget(decrypt_button)
self.download_dec_button = QPushButton("Download🔽")
self.download_dec_button.setEnabled(False)
self.download_dec_button.clicked.connect(lambda: self.download_image())
button_layout.addWidget(self.download_dec_button)
button_layout_widget = QWidget()
button_layout_widget.setLayout(button_layout)
self.main_layout.addWidget(button_layout_widget)
def show_image_hiding_page(self):
self.main_content.set_background_image("assets/components_backgrounds/main_window_bg.png")
self.secret_image_filepath = None
self.cover_image_filepath = None
# Clear the main window layout
self.clear_main_layout()
# Add content to the super resolution page
title_label = QLabel("<H2>STEGO CNN : Steganography Hide</H2>")
title_label.setStyleSheet("font-size: 24px; color: #ffffff;")
title_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(title_label)
# STEGO CNN model path label
model_path_label = QLabel("<h5>Model Path: InvisiCipher/app/models/DEEP_STEGO/models/hide.h5</h5>")
model_path_label.setStyleSheet("font-size: 16px; color: #c6c6c6;")
model_path_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(model_path_label)
# GPU Info
gpu_info_label = QLabel("<b><ul><li>Device: GPU:0 with 1654 MB memory</li><li>NVIDIA GeForce RTX 3050 Laptop GPU</li><li>Compute capability: 8.6</li><li>Loaded cuDNN version 8302</li></ul></b>")
gpu_info_label.setStyleSheet("font-size: 13px; color: #fae69e;")
gpu_info_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(gpu_info_label)
# label layout
label_layout = QHBoxLayout()
cover_text_label = QLabel("Select cover image:")
cover_text_label.setAlignment(Qt.AlignCenter)
cover_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(cover_text_label)
secret_text_label = QLabel("Select secret image:")
secret_text_label.setAlignment(Qt.AlignCenter)
secret_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(secret_text_label)
steg_text_label = QLabel("Generated steg image:")
steg_text_label.setAlignment(Qt.AlignCenter)
steg_text_label.setStyleSheet("font-size: 16px; color: #00ff00; margin-bottom: 10px; font-weight: bold;")
label_layout.addWidget(steg_text_label)
label_layout_widget = QWidget()
label_layout_widget.setLayout(label_layout)
self.main_layout.addWidget(label_layout_widget)
# Image display layout
image_display_layout = QHBoxLayout()
self.cover_display_label = QLabel()
self.cover_display_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/cover_image_dummy.png")
self.cover_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_display_layout.addWidget(self.cover_display_label)
self.secret_display_label = QLabel()
self.secret_display_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/secret_image_dummy.png")
self.secret_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_display_layout.addWidget(self.secret_display_label)
self.steg_display_label = QLabel()
self.steg_display_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/steg_image_dummy.png")
self.steg_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_display_layout.addWidget(self.steg_display_label)
image_display_layout_widget = QWidget()
image_display_layout_widget.setLayout(image_display_layout)
self.main_layout.addWidget(image_display_layout_widget)
# button layout
button_layout = QHBoxLayout()
clear_button = QPushButton("Clear")
clear_button.clicked.connect(lambda: self.show_image_hiding_page())
button_layout.addWidget(clear_button)
browse_cover_button = QPushButton("Browse cover image")
browse_cover_button.clicked.connect(lambda: self.select_cover_image(self.cover_display_label))
button_layout.addWidget(browse_cover_button)
browse_secret_button = QPushButton("Browse secret image")
browse_secret_button.clicked.connect(lambda: self.select_secret_image(self.secret_display_label))
button_layout.addWidget(browse_secret_button)
hide_button = QPushButton("Hide")
hide_button.clicked.connect(lambda: self.perform_hide(self.cover_image_filepath, self.secret_image_filepath))
button_layout.addWidget(hide_button)
self.download_steg_button = QPushButton("Download steg image🔽")
self.download_steg_button.setEnabled(False)
self.download_steg_button.clicked.connect(lambda: self.download_image())
button_layout.addWidget(self.download_steg_button)
button_layout_widget = QWidget()
button_layout_widget.setLayout(button_layout)
self.main_layout.addWidget(button_layout_widget)
def show_reveal_page(self):
self.main_content.set_background_image("assets/components_backgrounds/main_window_bg.png")
self.clear_main_layout()
# Add content to the super resolution page
title_label = QLabel("<H2>STEGO CNN : Steganography Reveal</H2>")
title_label.setStyleSheet("font-size: 24px; color: #ffffff;")
title_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(title_label)
# STEGO CNN model path label
model_path_label = QLabel("<h5>Model Path: InvisiCipher/app/models/DEEP_STEGO/models/reveal.h5</h5>")
model_path_label.setStyleSheet("font-size: 16px; color: #c6c6c6;")
model_path_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(model_path_label)
# GPU Info
gpu_info_label = QLabel("<b><ul><li>Device: GPU:0 with 1654 MB memory</li><li>NVIDIA GeForce RTX 3050 Laptop GPU</li><li>Compute capability: 8.6</li><li>Loaded cuDNN version 8302</li></ul></b>")
gpu_info_label.setStyleSheet("font-size: 13px; color: #fae69e;")
gpu_info_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(gpu_info_label)
# image text layout
image_text_layout = QHBoxLayout()
container_text_label = QLabel("Select steg image:")
container_text_label.setAlignment(Qt.AlignCenter)
container_text_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
image_text_layout.addWidget(container_text_label)
secret_out_text_label = QLabel("Revealed secret image:")
secret_out_text_label.setAlignment(Qt.AlignCenter)
secret_out_text_label.setStyleSheet("font-size: 16px; color: #00ff00; margin-bottom: 10px; font-weight: bold;")
image_text_layout.addWidget(secret_out_text_label)
image_text_layout_widget = QWidget()
image_text_layout_widget.setLayout(image_text_layout)
self.main_layout.addWidget(image_text_layout_widget)
# Image display layout
image_layout = QHBoxLayout()
self.container_display_label = QLabel()
self.container_display_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/steg_image_dummy.png")
self.container_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_layout.addWidget(self.container_display_label)
self.secret_out_display_label = QLabel()
self.secret_out_display_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/secret_image_dummy.png")
self.secret_out_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
image_layout.addWidget(self.secret_out_display_label)
image_layout_widget = QWidget()
image_layout_widget.setLayout(image_layout)
self.main_layout.addWidget(image_layout_widget)
# button layout
button_layout = QHBoxLayout()
clear_button = QPushButton("Clear")
clear_button.clicked.connect(lambda: self.show_reveal_page())
button_layout.addWidget(clear_button)
browse_cover_button = QPushButton("Browse steg image")
browse_cover_button.clicked.connect(lambda: self.select_container_image(self.container_display_label))
button_layout.addWidget(browse_cover_button)
reveal_button = QPushButton("Reveal")
reveal_button.clicked.connect(lambda: self.perform_reveal(self.container_image_filepath))
button_layout.addWidget(reveal_button)
self.download_revealed_secret_image_button = QPushButton("Download🔽")
self.download_revealed_secret_image_button.setEnabled(False)
self.download_revealed_secret_image_button.clicked.connect(lambda: self.download_image())
button_layout.addWidget(self.download_revealed_secret_image_button)
button_layout_widget = QWidget()
button_layout_widget.setLayout(button_layout)
self.main_layout.addWidget(button_layout_widget)
def show_super_resolution_page(self):
self.main_content.set_background_image("assets/components_backgrounds/main_window_bg.png")
self.low_res_image_filepath = None
# Clear the main window layout
self.clear_main_layout()
# Add content to the super resolution page
title_label = QLabel("<H2>Enhanced Super Resolution using ESRGAN</H2>")
title_label.setAlignment(Qt.AlignTop)
title_label.setStyleSheet("font-size: 24px; color: #ffffff; margin-bottom: 20px;")
self.main_layout.addWidget(title_label)
# ESRGAN model path label
model_path_label = QLabel("<h5>Model Path: InvisiCipher/app/models/ESRGAN/models/RRDB_ESRGAN_x4.pth</h5>")
model_path_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 20px;")
model_path_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(model_path_label)
# GPU Info
gpu_info_label = QLabel(
"<b><ul><li>Device: GPU:0 with 1654 MB memory</li><li>NVIDIA GeForce RTX 3050 Laptop GPU</li><li>Compute capability: 8.6</li><li>Loaded cuDNN version 8302</li></ul></b>")
gpu_info_label.setStyleSheet("font-size: 13px; color: #fae69e;")
gpu_info_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(gpu_info_label)
# Low resolution image selection
low_res_label = QLabel("Select Low Resolution Image:")
low_res_label.setAlignment(Qt.AlignCenter)
low_res_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 10px; font-weight: bold;")
self.main_layout.addWidget(low_res_label)
# image display
image_label = QLabel()
image_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/lr_image_dummy.png")
image_label.setPixmap(pixmap.scaled(384, 384, Qt.KeepAspectRatio))
self.main_layout.addWidget(image_label)
# defining button layout
button_layout = QHBoxLayout()
# Browse button
clear_button = QPushButton("Clear")
clear_button.clicked.connect(lambda: self.show_super_resolution_page())
button_layout.addWidget(clear_button)
browse_button = QPushButton("Browse")
browse_button.clicked.connect(lambda: self.select_low_resolution_image(image_label))
button_layout.addWidget(browse_button)
# Up-scale button
upscale_button = QPushButton("UP-SCALE")
upscale_button.clicked.connect(lambda: self.upscaleImage(image_label))
button_layout.addWidget(upscale_button)
# Download button
download_button = QPushButton("Download🔽")
download_button.setObjectName("download_button")
download_button.setEnabled(False)
download_button.clicked.connect(self.download_image)
button_layout.addWidget(download_button)
# add the button layout to the main layout
button_widget = QWidget()
button_widget.setLayout(button_layout)
self.main_layout.addWidget(button_widget)
# Set the image labels as attributes
self.low_res_image_text_label = low_res_label
self.image_label = image_label
self.download_HR_button = download_button
def show_imagegen_page(self):
self.main_content.set_background_image("assets/components_backgrounds/main_window_bg.png")
self.clear_main_layout()
# Add content to the super resolution page
title_label = QLabel("<H2>StackGAN : Image generation using GenAI</H2>")
title_label.setStyleSheet("font-size: 24px; color: #ffffff;")
title_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(title_label)
# StackGAN model path label
model_path_label = QLabel("<h5>Model Path: InvisiCipher/app/models/StackGAN/models/<h5>")
model_path_label.setStyleSheet("font-size: 16px; color: #c6c6c6; margin-bottom: 20px;")
model_path_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(model_path_label)
# GPU Info
gpu_info_label = QLabel(
"<b><ul><li>Device: GPU:0 with 1654 MB memory</li><li>NVIDIA GeForce RTX 3050 Laptop GPU</li><li>Compute capability: 8.6</li><li>Loaded cuDNN version 8302</li></ul></b>")
gpu_info_label.setStyleSheet("font-size: 13px; color: #fae69e;")
gpu_info_label.setAlignment(Qt.AlignTop)
self.main_layout.addWidget(gpu_info_label)
# image display
self.gen_image_label = QLabel()
self.gen_image_label.setAlignment(Qt.AlignCenter)
pixmap = QPixmap("assets/dummy_images/imagegen_dummy.png")
self.gen_image_label.setPixmap(pixmap.scaled(384, 384, Qt.KeepAspectRatio))
self.main_layout.addWidget(self.gen_image_label)
# Text description enter prompt
image_desc_label = QLabel("Your image description here👇🏻")
image_desc_label.setAlignment(Qt.AlignCenter)
image_desc_label.setStyleSheet("font-size: 16px; color: #c6c6c6; font-weight: semi-bold;")
self.main_layout.addWidget(image_desc_label)
# defining layout for textbox and i'm feeling lucky
textbox_layout = QHBoxLayout()
# Create a QlineEdit widget
self.text_desc_box = CustomTextBoxForImageGen()
self.text_desc_box.setPlaceholderText("Type here....")
textbox_layout.addWidget(self.text_desc_box)
# i'm feeling lucky button
lucky_button = QPushButton("I'm feeling lucky")
lucky_button.setObjectName("luckyButton")
lucky_button.setToolTip("Selects a random text prompt")
lucky_button.clicked.connect(lambda: self.show_random_text(self.text_desc_box))
textbox_layout.addWidget(lucky_button)
# add the textbox layout to the main layout
textbox_widget = QWidget()
textbox_widget.setLayout(textbox_layout)
self.main_layout.addWidget(textbox_widget)
# defining button layout
button_layout = QHBoxLayout()
# clear button
clear_button = QPushButton("Clear")
clear_button.clicked.connect(lambda: self.show_imagegen_page())
button_layout.addWidget(clear_button)
# generate button
generate_button = QPushButton("Generate✨")
generate_button.setObjectName("gen_button")
generate_button.clicked.connect(lambda: self.generateImage(self.gen_image_label))
button_layout.addWidget(generate_button)
# Download button
download_button = QPushButton("Download🔽")
download_button.setObjectName("download_button")
download_button.setEnabled(False)
download_button.clicked.connect(self.download_image)
button_layout.addWidget(download_button)
self.download_genimage_button = download_button
# add the button layout to the main layout
button_widget = QWidget()
button_widget.setLayout(button_layout)
self.main_layout.addWidget(button_widget)
def generateImage(self, label):
print("Image gen")
gen_image_path = 'C:/Users/asirw/PycharmProjects/InvisiCipher/app/generated_image.png'
if self.text_desc_box.text() == "":
QMessageBox.information(self, "Generation Error", "Please enter a description")
return
try:
image = StableDiffusionV2.generate(text_prompt=self.text_desc_box.text())
image.save(gen_image_path)
pixmap = QPixmap(gen_image_path)
label.setPixmap(pixmap.scaled(400, 400, Qt.KeepAspectRatio))
self.download_genimage_button.setEnabled(True)
except:
QMessageBox.critical(self, "Generating error", "Failed to generate the image")
def show_random_text(self, textbox):
import json, random
with open("C:/Users/asirw/PycharmProjects/InvisiCipher/app/ui/assets/json/lucky.json", "r") as f:
text = random.choice(json.load(f))
textbox.setText(text)
def select_low_resolution_image(self, label):
file_dialog = QFileDialog()
low_res_image_filepath, _ = file_dialog.getOpenFileName(self, "Select Low Resolution Image")
if low_res_image_filepath:
self.low_res_image_filepath = low_res_image_filepath
pixmap = QPixmap(low_res_image_filepath)
label.setPixmap(pixmap.scaled(400, 400, Qt.KeepAspectRatio))
def upscaleImage(self, label):
if self.low_res_image_filepath is None:
QMessageBox.information(self, "Upscaling Error", "Please select the low-resolution image first.")
return
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:400"
model_path = 'C:/Users/asirw/PycharmProjects/InvisiCipher/app/models/ESRGAN/models/RRDB_ESRGAN_x4.pth'
device = torch.device('cuda')
model = arch.RRDBNet(3, 3, 64, 23, gc=32)
model.load_state_dict(torch.load(model_path), strict=True)
model.eval()
model = model.to(device)
print('Model path {:s}. \nUp-scaling...'.format(model_path))
image = cv2.imread(self.low_res_image_filepath, cv2.IMREAD_COLOR)
image = image * 1.0 / 255
image = torch.from_numpy(np.transpose(image[:, :, [2, 1, 0]], (2, 0, 1))).float()
image_low_res = image.unsqueeze(0)
image_low_res = image_low_res.to(device)
with torch.no_grad():
image_high_res = model(image_low_res).data.squeeze().float().cpu().clamp_(0, 1).numpy()
image_high_res = np.transpose(image_high_res[[2, 1, 0], :, :], (1, 2, 0))
image_high_res = (image_high_res * 255.0).round()
high_res_image_path = os.path.abspath('upscaled.png')
cv2.imwrite(high_res_image_path, image_high_res)
# Display the high resolution image
if os.path.exists(high_res_image_path):
print("image saved as: ", high_res_image_path)
pixmap = QPixmap(high_res_image_path).scaled(400, 400, Qt.KeepAspectRatio)
label.setPixmap(pixmap)
self.low_res_image_text_label.setText("High Res Image:")
self.low_res_image_text_label.setStyleSheet(
"font-size: 16px; color: #00ff00; margin-bottom: 10px; font-weight: bold;")
self.download_HR_button.setEnabled(True)
else:
QMessageBox.critical(self, "Upscaling Error", "Failed to upscale the image.")
def download_image(self):
# Implement the logic to download the high resolution image
QMessageBox.information(self, "Download", "Downloaded the image...")
def clear_main_layout(self):
# Remove all widgets from the main layout
while self.main_layout.count():
child = self.main_layout.takeAt(0)
if child.widget():
child.widget().deleteLater()
def select_cover_image(self, label):
file_dialog = QFileDialog()
filepath, _ = file_dialog.getOpenFileName(self, "Select cover Image")
if filepath:
self.cover_image_filepath = filepath
pixmap = QPixmap(filepath)
label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
def select_secret_image(self, label):
file_dialog = QFileDialog()
filepath, _ = file_dialog.getOpenFileName(self, "Select secret Image")
if filepath:
self.secret_image_filepath = filepath
pixmap = QPixmap(filepath)
label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
def select_container_image(self, label):
file_dialog = QFileDialog()
filepath, _ = file_dialog.getOpenFileName(self, "Select secret Image")
if filepath:
self.container_image_filepath = filepath
pixmap = QPixmap(filepath)
label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
def select_enc_image(self, label):
file_dialog = QFileDialog()
filepath, _ = file_dialog.getOpenFileName(self, "Select Image")
if filepath:
self.image_tobe_enc_filepath = filepath
pixmap = QPixmap(filepath)
label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
def select_dec_image(self, label):
file_dialog = QFileDialog()
filepath, _ = file_dialog.getOpenFileName(self, "Select enc file")
if filepath:
self.enc_filepath = filepath
pixmap = QPixmap("assets/dummy_images/locked_image_dummy.png")
label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
def perform_hide(self, cover_filepath, secret_filepath):
if cover_filepath is None or secret_filepath is None:
QMessageBox.information(self, "Hiding Error", "Please select the images first.")
return
try:
hide_image(cover_filepath, secret_filepath)
steg_image_path = 'C:/Users/asirw/PycharmProjects/InvisiCipher/app/steg_image.png'
pixmap = QPixmap(steg_image_path)
self.steg_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
self.download_steg_button.setEnabled(True)
except:
QMessageBox.critical(self, "Hiding Error", "Failed to hide the image.")
def perform_reveal(self, filepath):
if filepath is None:
QMessageBox.information(self, "Revealing Error", "Please select the image first.")
return
try:
reveal_image(filepath)
secret_out_filepath = "C:/Users/asirw/PycharmProjects/InvisiCipher/app/secret_out.png"
pixmap = QPixmap(secret_out_filepath)
self.secret_out_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
self.download_revealed_secret_image_button.setEnabled(True)
except:
QMessageBox.critical(self, "Revealing error", "Failed to reveal the image")
def perform_encryption(self, filepath):
if filepath is None:
QMessageBox.information(self, "Encrypting Error", "Please select the image first.")
return
if not self.aes_radio.isChecked() and not self.blowfish_radio.isChecked():
QMessageBox.information(self, "Encrypting Error", "Please select an encryption method.")
return
if self.key_text_box.text() == "":
QMessageBox.information(self, "Encrypting Error", "Please enter a secret key")
return
try:
if self.aes_radio.isChecked():
aes.encrypt(filepath, self.key_text_box.text())
else:
blowfish.encrypt(filepath, self.key_text_box.text())
self.download_enc_button.setEnabled(True)
self.enc_img_text_label.setText("Encrypted!")
self.enc_img_text_label.setStyleSheet(
"font-size: 16px; color: #00ff00; margin-bottom: 10px; font-weight: bold;")
pixmap = QPixmap("assets/dummy_images/locked_image_dummy.png")
self.enc_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
self.key_text_box.setText("")
except:
QMessageBox.critical(self, "Encrypting error", "Failed to encryp the image")
def perform_decryption(self, filepath):
dec_filename = None
if filepath is None:
QMessageBox.information(self, "Decrypting Error", "Please select the image first.")
return
if not self.aes_radio_dec.isChecked() and not self.blowfish_radio_dec.isChecked():
QMessageBox.information(self, "Decrypting Error", "Please select an decryption method.")
return
if self.key_text_box_of_dec.text() == "":
QMessageBox.information(self, "Decrypting Error", "Please enter a secret key")
return
try:
if self.aes_radio_dec.isChecked():
result, dec_filename = aes.decrypt(filepath, self.key_text_box_of_dec.text())
if result == -1:
QMessageBox.critical(self, "Decrypting error", "Wrong Key! ")
return
else:
result, dec_filename = blowfish.decrypt(filepath, self.key_text_box_of_dec.text())
if result == -1:
QMessageBox.critical(self, "Decrypting error", "Wrong Key! ")
return
self.download_dec_button.setEnabled(True)
self.dec_img_text_label.setText("Decrypted!")
self.dec_img_text_label.setStyleSheet(
"font-size: 16px; color: #00ff00; margin-bottom: 10px; font-weight: bold;")
pixmap = QPixmap(dec_filename)
self.dec_display_label.setPixmap(pixmap.scaled(256, 256, Qt.KeepAspectRatio))
self.key_text_box_of_dec.setText("")
except:
QMessageBox.critical(self, "Decrypting error", "Failed to decrypt the file")
def logout(self):
dialog = QDialog(self)
dialog.setWindowTitle("Exit")
dialog.setMinimumSize(450, 100)
layout = QVBoxLayout(dialog)
msg_box = QMessageBox()
msg_box.setText("<h3>Are you sure you want to Exit?</h3>")
# Set custom font and size
font = QFont("Arial", 12) # Adjust the font and size as desired
msg_box.setFont(font)
button_layout = QHBoxLayout()
layout.addWidget(msg_box)
layout.addLayout(button_layout)
# Remove the standard buttons
msg_box.setStandardButtons(QMessageBox.NoButton)
yes_button = QPushButton("Yes")
yes_button.setStyleSheet("color: #000000;")
yes_button.clicked.connect(lambda: QApplication.quit())
no_button = QPushButton("No")
no_button.setStyleSheet("color: #000000;")
no_button.clicked.connect(dialog.reject)
button_layout.addWidget(yes_button)
button_layout.addWidget(no_button)
dialog.exec_()
def load_stylesheet(self):
stylesheet = QFile("styles/style.qss")
if stylesheet.open(QFile.ReadOnly | QFile.Text):
stream = QTextStream(stylesheet)
self.setStyleSheet(stream.readAll())
# Create the application
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
app = QApplication(sys.argv)
window = MainAppWindow()
window.load_stylesheet()
window.show()
sys.exit(app.exec_())
|