Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

174 linhas
4.1 KiB

  1. import sys
  2. from PyQt5.uic import loadUi
  3. from PyQt5 import QtWidgets
  4. from PyQt5.QtWidgets import QDialog, QApplication, QWidget, QLabel, QScrollArea, QVBoxLayout, QFrame, QComboBox
  5. from PyQt5.QtGui import QPixmap
  6. import firebase_admin
  7. from firebase_admin import credentials, auth, db, initialize_app
  8. import os
  9. current_directory = os.path.dirname(os.path.realpath(__file__))
  10. json_path = os.path.join(current_directory, 'chatbot.json')
  11. #cred = credentials.Certificate('/home/knight/ChatBot_UI/chatbot.json')
  12. cred = credentials.Certificate(json_path)
  13. firebase_admin.initialize_app(cred, {'databaseURL': 'https://chatbot-402717-default-rtdb.firebaseio.com/'})
  14. class RoundedVBoxLayout(QVBoxLayout):
  15. def __init__(self):
  16. super().__init__()
  17. self.rounded_frame = QFrame()
  18. self.rounded_frame.setStyleSheet("QFrame {border-radius: 50px; background-color: lightgray;}")
  19. self.rounded_frame.setLayout(self)
  20. def addWidget(self, widget):
  21. # Add widgets to the rounded frame
  22. super().addWidget(widget)
  23. class LoginScreen(QDialog):
  24. def __init__(self):
  25. super(LoginScreen, self).__init__()
  26. loadUi("login.ui",self)
  27. self.passwordfield.setEchoMode(QtWidgets.QLineEdit.Password)
  28. self.loginButton.clicked.connect(self.loginfunction)
  29. #self.loginButton.clicked.connect(self.gotoDashboard)
  30. def loginfunction(self):
  31. username = self.emailfield.text()
  32. password = self.passwordfield.text()
  33. if len(username)==0 or len(password)==0:
  34. self.labelError.setText("Please input all fields.")
  35. else:
  36. try:
  37. user = auth.get_user_by_email(username)
  38. if user:
  39. self.gotoDashboard()
  40. except:
  41. print("Login Failed !")
  42. self.labelError.setText("Login Failed Invalid Username or Password")
  43. def gotoDashboard(self):
  44. dashBoard = DashBoard()
  45. widget.addWidget(dashBoard)
  46. widget.setCurrentIndex(widget.currentIndex()+1)
  47. class DashBoard(QDialog):
  48. def __init__(self):
  49. super(DashBoard, self).__init__()
  50. loadUi('dashboard.ui', self)
  51. self.ref = db.reference('/intents_and_questions')
  52. self.layout = self.questionLayout
  53. self.show_intents_questions()
  54. self.get_intents()
  55. def update_intent(self):
  56. pass
  57. def update_question(self):
  58. pass
  59. def get_intents(self):
  60. self.intentCombo.setContentsMargins(40, 140, 0, 0)
  61. data = self.ref.get()
  62. if data:
  63. self.intentCombo.addItems(list(data.keys()))
  64. else:
  65. self.intentCombo.addItems([])
  66. def show_intents_questions(self):
  67. data = self.ref.get()
  68. if data:
  69. # Assuming data is a dictionary
  70. for intent, questions in data.items():
  71. questions_text = '\n'.join(questions)
  72. #label_text = f"Intent: {intent}\nQuestions:{questions_text}\n{'-'*50}"
  73. label_text = f"INTENT : {intent}\n\nQUESTIONS : \n{questions_text}\n{'-'*50}"
  74. label = QLabel(label_text)
  75. label.setContentsMargins(20,20,20,20)
  76. self.layout.addWidget(label)
  77. scroll_area = QScrollArea()
  78. scroll_area.setWidgetResizable(True)
  79. scroll_widget = QWidget()
  80. scroll_widget.setLayout(self.layout)
  81. scroll_area.setWidget(scroll_widget)
  82. #main_layout = QVBoxLayout()
  83. main_layout = RoundedVBoxLayout()
  84. main_layout.addWidget(scroll_area)
  85. main_layout.setContentsMargins(20, 120, 800, 30)
  86. self.setLayout(main_layout)
  87. self.setGeometry(300, 300, 400, 200)
  88. self.setWindowTitle('Dashboard')
  89. self.show()
  90. app = QApplication(sys.argv)
  91. welcome = LoginScreen()
  92. widget = QtWidgets.QStackedWidget()
  93. widget.addWidget(welcome)
  94. widget.setFixedHeight(800)
  95. widget.setFixedWidth(1200)
  96. widget.show()
  97. try:
  98. sys.exit(app.exec_())
  99. except:
  100. print("Exiting")