commit f79dc4630defc6a8a458a32ada8ef6aa80d57fc1 Author: nitin2606 Date: Mon Dec 18 10:28:20 2023 +0530 initial_commit diff --git a/Friendly_new.mp4 b/Friendly_new.mp4 new file mode 100644 index 0000000..c1bbd07 Binary files /dev/null and b/Friendly_new.mp4 differ diff --git a/admin_panel.py b/admin_panel.py new file mode 100644 index 0000000..1b5c4d0 --- /dev/null +++ b/admin_panel.py @@ -0,0 +1,174 @@ +import sys +from PyQt5.uic import loadUi +from PyQt5 import QtWidgets +from PyQt5.QtWidgets import QDialog, QApplication, QWidget, QLabel, QScrollArea, QVBoxLayout, QFrame, QComboBox +from PyQt5.QtGui import QPixmap +import firebase_admin +from firebase_admin import credentials, auth, db, initialize_app + +import os + + + +current_directory = os.path.dirname(os.path.realpath(__file__)) + +json_path = os.path.join(current_directory, 'chatbot.json') + +#cred = credentials.Certificate('/home/knight/ChatBot_UI/chatbot.json') +cred = credentials.Certificate(json_path) +firebase_admin.initialize_app(cred, {'databaseURL': 'https://chatbot-402717-default-rtdb.firebaseio.com/'}) + + + +class RoundedVBoxLayout(QVBoxLayout): + + def __init__(self): + + super().__init__() + + self.rounded_frame = QFrame() + + self.rounded_frame.setStyleSheet("QFrame {border-radius: 50px; background-color: lightgray;}") + self.rounded_frame.setLayout(self) + + + def addWidget(self, widget): + # Add widgets to the rounded frame + super().addWidget(widget) + + + + +class LoginScreen(QDialog): + + def __init__(self): + super(LoginScreen, self).__init__() + loadUi("login.ui",self) + + self.passwordfield.setEchoMode(QtWidgets.QLineEdit.Password) + + self.loginButton.clicked.connect(self.loginfunction) + #self.loginButton.clicked.connect(self.gotoDashboard) + + def loginfunction(self): + username = self.emailfield.text() + password = self.passwordfield.text() + + if len(username)==0 or len(password)==0: + self.labelError.setText("Please input all fields.") + + else: + + try: + user = auth.get_user_by_email(username) + + if user: + self.gotoDashboard() + + except: + print("Login Failed !") + self.labelError.setText("Login Failed Invalid Username or Password") + + + def gotoDashboard(self): + + dashBoard = DashBoard() + widget.addWidget(dashBoard) + widget.setCurrentIndex(widget.currentIndex()+1) + + +class DashBoard(QDialog): + + def __init__(self): + super(DashBoard, self).__init__() + loadUi('dashboard.ui', self) + + self.ref = db.reference('/intents_and_questions') + + self.layout = self.questionLayout + self.show_intents_questions() + + + + self.get_intents() + + + + def update_intent(self): + + pass + + + def update_question(self): + + pass + + + def get_intents(self): + + + + self.intentCombo.setContentsMargins(40, 140, 0, 0) + + data = self.ref.get() + + if data: + self.intentCombo.addItems(list(data.keys())) + + else: + self.intentCombo.addItems([]) + + + def show_intents_questions(self): + + + + data = self.ref.get() + + if data: + # Assuming data is a dictionary + for intent, questions in data.items(): + questions_text = '\n'.join(questions) + #label_text = f"Intent: {intent}\nQuestions:{questions_text}\n{'-'*50}" + label_text = f"INTENT : {intent}\n\nQUESTIONS : \n{questions_text}\n{'-'*50}" + label = QLabel(label_text) + label.setContentsMargins(20,20,20,20) + self.layout.addWidget(label) + + + + + scroll_area = QScrollArea() + scroll_area.setWidgetResizable(True) + + scroll_widget = QWidget() + scroll_widget.setLayout(self.layout) + scroll_area.setWidget(scroll_widget) + + #main_layout = QVBoxLayout() + main_layout = RoundedVBoxLayout() + main_layout.addWidget(scroll_area) + + main_layout.setContentsMargins(20, 120, 800, 30) + + + self.setLayout(main_layout) + self.setGeometry(300, 300, 400, 200) + self.setWindowTitle('Dashboard') + self.show() + + + +app = QApplication(sys.argv) +welcome = LoginScreen() +widget = QtWidgets.QStackedWidget() +widget.addWidget(welcome) +widget.setFixedHeight(800) +widget.setFixedWidth(1200) +widget.show() + + +try: + sys.exit(app.exec_()) +except: + print("Exiting") \ No newline at end of file diff --git a/chatbot.json b/chatbot.json new file mode 100644 index 0000000..eeabc5e --- /dev/null +++ b/chatbot.json @@ -0,0 +1,13 @@ +{ + "type": "service_account", + "project_id": "chatbot-402717", + "private_key_id": "a8af9eb772aee6b957ee35dd990c2f29d2beb4b2", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQ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A/24\n6V0Wdf6x0QKBgATXwimZWG55zAlozyUMq96ucVWgN1ZpMOfE0XFfqK6TT/yO9pBF\nSCoUlo6atLshwu40+nlEKTxb5u5muZyCkG5d+0XQ5X/aFztA4jz2mZghfUYlt3A1\nJxr+3vVjdWKW6B80AjCtudOJZDJf7Wr5DINzY94Uv3c5KU277C+L8eHhAoGAV8iP\nomSnaq9t5O/jJ73diNNyffyMWVoluOi8OuoSxOvL5gbtopvxtJIJQ+giAsluetCd\nMtxnpotv5Dd1xQzLIyg4CsxVe0dVIosJRolOto/6XSuRzLOrCa1kEhI0gl9wffC6\nnP6bomh6HCZBnOJRg8Eu+iDiJbZoKNWSbhfCVkECgYEAixIjtmZ8IbatLSnVs6N4\nHz9b/wLKK+nyXq2hRBmWRbBXlXDxasKavLZ/OgmtM9/R8vMrwVKvJloRVhbnK1/q\n8DrVrgFn3pJOXtzrnNtQkR6Y5uYi7cn6DVI9RhObXqY1XhLZDX4acJTSRgvUUdu8\nMuXeZr6PsBwGM5nlBTTT6Hg=\n-----END PRIVATE KEY-----\n", + "client_email": "firebase-adminsdk-7gtu4@chatbot-402717.iam.gserviceaccount.com", + "client_id": "104666490557463603037", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-7gtu4%40chatbot-402717.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" +} diff --git a/dashboard.ui b/dashboard.ui new file mode 100644 index 0000000..14392b1 --- /dev/null +++ b/dashboard.ui @@ -0,0 +1,102 @@ + + + Dialog + + + + 0 + 0 + 1200 + 800 + + + + Dialog + + + + + 0 + 0 + 1201 + 801 + + + + QWidget#bgwidget { + background-color: qlineargradient(spread: pad, x1: 0.091, y1: 0.101636, x2: 0.991379, y2: 0.977, stop: 0 rgba(30, 30, 40, 255), stop: 1 rgba(50, 50, 80, 255)); +} + + + + + + + 480 + 10 + 262 + 57 + + + + font: 36pt "MS Shell Dlg 2"; color:rgb(255, 255, 255) + + + Dashboard + + + Qt::AlignCenter + + + + + + 30 + 100 + 441 + 691 + + + + + + + + 0 + 60 + 311 + 31 + + + + color: rgb(255, 255, 255); +font: 75 15pt "Waree"; + + + Questions and Intents + + + Qt::AlignCenter + + + + + + 480 + 126 + 230 + 24 + + + + + 75 + true + + + + + + + + diff --git a/login.ui b/login.ui new file mode 100644 index 0000000..9e60b78 --- /dev/null +++ b/login.ui @@ -0,0 +1,188 @@ + + + Dialog + + + + 0 + 0 + 1200 + 800 + + + + Admin Panel + + + + + 0 + 0 + 1200 + 800 + + + + QWidget#bgwidget { + background-color: qlineargradient(spread: pad, x1: 0.091, y1: 0.101636, x2: 0.991379, y2: 0.977, stop: 0 rgba(30, 30, 40, 255), stop: 1 rgba(50, 50, 80, 255)); +} + + + + + + + 490 + 110 + 251 + 71 + + + + font: 36pt "MS Shell Dlg 2"; color:rgb(255, 255, 255) + + + WELCOME + + + Qt::AlignCenter + + + + + + 420 + 200 + 391 + 41 + + + + font: 16pt "MS Shell Dlg 2";color:rgb(255, 255, 255) + + + Sign in to your existing account + + + Qt::AlignCenter + + + + + + 440 + 490 + 341 + 51 + + + + border-radius:20px; +background-color: rgb(170, 255, 255); +font: 14pt "MS Shell Dlg 2"; + + + Log in + + + + + + 440 + 290 + 341 + 51 + + + + + 15 + 0 + + + + background-color:rgba(0,0,0,0); +font: 12pt "MS Shell Dlg 2"; +color: rgb(255, 255, 255); + + + + + + + 440 + 390 + 341 + 51 + + + + background-color:rgba(0,0,0,0); +font: 12pt "MS Shell Dlg 2"; +color: rgb(255, 255, 255); + + + + + + 440 + 270 + 81 + 20 + + + + + MS Shell Dlg 2 + 10 + 50 + false + false + + + + font: 10pt "MS Shell Dlg 2"; +color: rgb(255, 255, 255); + + + Username + + + + + + 440 + 370 + 81 + 20 + + + + font: 10pt "MS Shell Dlg 2"; +color: rgb(255, 255, 255); + + + Password + + + + + + 440 + 456 + 341 + 20 + + + + font: 12pt "MS Shell Dlg 2"; color:red; + + + + + + + + + + diff --git a/main_ui.py b/main_ui.py new file mode 100644 index 0000000..5ee8dac --- /dev/null +++ b/main_ui.py @@ -0,0 +1,124 @@ +import sys +from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QPushButton, QLabel, QVBoxLayout, QWidget +from PyQt5.QtMultimediaWidgets import QVideoWidget +from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent +from PyQt5.QtCore import QUrl +import speech_recognition as sr +import question +import os + + + +current_directory = os.path.dirname(os.path.realpath(__file__)) +main_video_path = os.path.join(current_directory, 'Friendly_new.mp4') + +class HospitalChatbotGUI(QMainWindow): + + def __init__(self): + super().__init__() + + + self.setWindowTitle("Hospital Chatbot") + self.setGeometry(100, 100, 800, 600) + self.central_widget = QWidget(self) + self.setCentralWidget(self.central_widget) + self.layout = QVBoxLayout() + + + #self.submit_button = QPushButton("Submit", self) + #self.submit_button.clicked.connect(self.get_response) + #self.layout.addWidget(self.submit_button) + + self.speak_button = QPushButton("Speak", self) + self.speak_button.clicked.connect(self.audio_to_text) + self.layout.addWidget(self.speak_button) + + + self.video_widget = QVideoWidget(self) + self.layout.addWidget(self.video_widget) + #self.video_widget.setFixedWidth(500) + + self.central_widget.setLayout(self.layout) + + self.media_player = QMediaPlayer() + self.media_player.setVideoOutput(self.video_widget) + self.media_player.mediaStatusChanged.connect(self.handle_media_status_changed) + + + + #self.sample_video_url = "/home/knight/ChatBot_UI/Friendly_new.mp4" + self.sample_video_url = main_video_path + + + self.answer_video_url = None + self.play_video(self.sample_video_url) + + + + + def audio_to_text(self): + + init_rec = sr.Recognizer() + print("Let's speak!!") + with sr.Microphone(3) as source: + audio_data = init_rec.record(source, duration=2) + print("Recognizing your text.............") + text = init_rec.recognize_google(audio_data) + + self.get_response(text.strip()) + print(text) + + + + def get_response(self,text): + video_url = None + print("Response Text: ",text) + + user_input = text.strip() + + lowercase_text = user_input.lower() + + matching_intent = [intent for intent, questions in question.intents_and_question.items() if any(q in lowercase_text for q in questions)] + + if matching_intent: + print("Intent: ", matching_intent[0]) + video_url = question.get_video_response(matching_intent[0]) + else: + print("No matching intent found.") + + if video_url: + + + self.play_video(video_url) + return + matching_intent = None + + #self.play_video("/home/knight/ChatBot_UI/Friendly_new.mp4") + self.play_video(main_video_path) + + + + + def play_video(self, video_url): + + media_content = QMediaContent(QUrl.fromLocalFile(video_url)) + self.media_player.setMedia(media_content) + self.media_player.play() + + + def handle_media_status_changed(self, status): + if status == QMediaPlayer.EndOfMedia: + print("Video finished playing.") + #self.play_video("/home/knight/ChatBot_UI/Friendly_new.mp4") + self.play_video(main_video_path) + + + + + +if __name__ == '__main__': + app = QApplication(sys.argv) + window = HospitalChatbotGUI() + window.show() + + sys.exit(app.exec_()) \ No newline at end of file diff --git a/question.py b/question.py new file mode 100644 index 0000000..ed2d3de --- /dev/null +++ b/question.py @@ -0,0 +1,217 @@ +import os + + +current_directory = os.path.dirname(os.path.realpath(__file__)) + +intents_and_question = { + + "greet": [ + + "hey", + "hello", + "Hello?", + "hello?", + "hi", + "hello there", + "good morning", + "good evening", + "moin", + "hey there", + "let's go", + "hey dude", + "goodmorning", + "goodevening", + "good afternoon" + ], + + + + "appointment_booking": [ + + "How can I schedule an appointment", + "I need to book an appointment with a doctor", + "what's the procedure for booking an appointment", + "hello, I'd like to schedule an appointment.", + "book an appointment", + "appointment", + "need an appointment" + ], + + + "doctor_information": [ + + "tell me more about dr. abc", + "what's the specialty of dr. abc", + "give me the contact details for dr. abc" + "doctor", + "contact doctor", + "doctor contact", + "doctor detail", + "detail doctor" + + ], + + + "department_information": [ + + "which departments are available in the hospital", + "can you provide details about the cardiology department", + "tell me more about the pediatric department", + "department", + "which department", + "department info" + + ], + + + "visiting_hours":[ + + "what are the visiting hours for patients", + "when can I visit a patient in the hospital", + "is there a specific time for visiting hours", + "visiting time", + "visit", + "time", + "time to visit", + "visit time", + "hospital visit", + "visit hospital" + ], + + + "location_and_directions":[ + + "how do I get to the hospital", + "can you provide me with directions to your location", + "where is the hospital situated", + "direction", + "direction hospital", + "hospital direction", + "location", + "hospital location" + ], + + + "billing_and_insurance": [ + + "how do I pay my medical bills", + "do you accept my insurance", + "what's the billing process for a hospital stay", + "bills", + "insurance", + "pay bill", + ], + + + "medical_records": [ + "how can I access my medical records", + "request my medical history", + "I need a copy of my lab results", + "medical records", + "medical record", + "record", + "records", + "record medical", + "results", + "lab results", + "result copy", + "copy result" + ], + + + "emergency_services": [ + "what should I do in case of a medical emergency", + "how do I contact the hospital in an emergency", + "tell me about your emergency services", + "emergency", + "emergency service" + ], + + + "covid19_information": [ + "what safety measures are in place due to COVID-19", + "is it safe to visit the hospital during the pandemic", + "do you offer COVID-19 testing or vaccinations", + "covid19" + + ], + + + "feedback_and_complaints": [ + "I want to provide feedback about my experience", + "how can I file a complaint about a staff member", + "share my thoughts on my recent visit", + "feedback", + "complaints", + "complain", + "share thoughts", + "experiance" + ], + + + "general_information": [ + "tell me more about the hospital", + "what services do you offer", + "is there a cafeteria in the hospital", + "information", + "cafeteria", + "services", + "services offered", + "offered services" + ] + +} + + +'''video_urls = { + + "greet": "/home/knight/ChatBot_UI/video/greet.mp4", + "appointment_booking": "/home/knight/ChatBot_UI/video/appointment_booking.mp4", + "doctor_information": "/home/knight/ChatBot_UI/video/doctor_information.mp4", + "department_information": "/home/knight/ChatBot_UI/video/department_information.mp4", + "visiting_hours": "/home/knight/ChatBot_UI/video/visiting_hours.mp4", + "location_and_directions": "/home/knight/ChatBot_UI/video/location_and_directions.mp4", + "billing_and_insurance": "/home/knight/ChatBot_UI/video/billing_and_insurance.mp4", + "medical_records": "/home/knight/ChatBot_UI/video/medical_records.mp4", + "emergency_assistance": "/home/knight/ChatBot_UI/video/emergency_services.mp4", + "covid19_information": "/home/knight/ChatBot_UI/video/covid19_information.mp4", + "feedback_and_complaints": "/home/knight/ChatBot_UI/video/feedback_and_complaints.mp4", + "thank_you": "/home/knight/ChatBot_UI/video/thank_you.mp4", + "general_information": "/home/knight/ChatBot_UI/video/general_information.mp4" + + + }''' + + + +video_urls = { + + "greet": os.path.join(current_directory, 'video', 'greet.mp4'), + "appointment_booking": os.path.join(current_directory, 'video', 'appointment_booking.mp4'), + "doctor_information": os.path.join(current_directory, 'video', 'doctor_information.mp4'), + "department_information": os.path.join(current_directory, 'video' ,'department_information.mp4'), + "visiting_hours": os.path.join(current_directory, 'video', 'visiting_hours.mp4'), + "location_and_directions": os.path.join(current_directory, 'video','location_and_directions.mp4'), + "billing_and_insurance": os.path.join(current_directory, 'video', 'billing_and_insurance.mp4'), + "medical_records": os.path.join(current_directory, 'video', 'medical_records.mp4'), + "emergency_assistance": os.path.join(current_directory, 'video','emergency_services.mp4'), + "covid19_information": os.path.join(current_directory, 'video','covid19_information.mp4'), + "feedback_and_complaints": os.path.join(current_directory, 'video','feedback_and_complaints.mp4'), + "thank_you": os.path.join(current_directory, 'video','video/thank_you.mp4'), + "general_information": os.path.join(current_directory, 'video','general_information.mp4') + + + } + + +def get_video_response(intent): + + return video_urls.get(intent) + + + +#print(get_video_response('greet')) + + + + diff --git a/video/appointment_booking.mp4 b/video/appointment_booking.mp4 new file mode 100644 index 0000000..03fa490 Binary files /dev/null and b/video/appointment_booking.mp4 differ diff --git a/video/billing_and_insurance.mp4 b/video/billing_and_insurance.mp4 new file mode 100644 index 0000000..0e8e06b Binary files /dev/null and b/video/billing_and_insurance.mp4 differ diff --git a/video/covid19_information.mp4 b/video/covid19_information.mp4 new file mode 100644 index 0000000..5b0a499 Binary files /dev/null and b/video/covid19_information.mp4 differ diff --git a/video/department_information.mp4 b/video/department_information.mp4 new file mode 100644 index 0000000..8ff9297 Binary files /dev/null and b/video/department_information.mp4 differ diff --git a/video/doctor_information.mp4 b/video/doctor_information.mp4 new file mode 100644 index 0000000..f478a70 Binary files /dev/null and b/video/doctor_information.mp4 differ diff --git a/video/emergency_services.mp4 b/video/emergency_services.mp4 new file mode 100644 index 0000000..032f0ad Binary files /dev/null and b/video/emergency_services.mp4 differ diff --git a/video/feedback_and_complaints.mp4 b/video/feedback_and_complaints.mp4 new file mode 100644 index 0000000..d3a6b9c Binary files /dev/null and b/video/feedback_and_complaints.mp4 differ diff --git a/video/general_information.mp4 b/video/general_information.mp4 new file mode 100644 index 0000000..3e238b6 Binary files /dev/null and b/video/general_information.mp4 differ diff --git a/video/greet.mp4 b/video/greet.mp4 new file mode 100644 index 0000000..e9456e5 Binary files /dev/null and b/video/greet.mp4 differ diff --git a/video/location_and_directions.mp4 b/video/location_and_directions.mp4 new file mode 100644 index 0000000..b7f3980 Binary files /dev/null and b/video/location_and_directions.mp4 differ diff --git a/video/medical_records.mp4 b/video/medical_records.mp4 new file mode 100644 index 0000000..5554e2a Binary files /dev/null and b/video/medical_records.mp4 differ diff --git a/video/thank_you.mp4 b/video/thank_you.mp4 new file mode 100644 index 0000000..73814cc Binary files /dev/null and b/video/thank_you.mp4 differ diff --git a/video/visiting_hours.mp4 b/video/visiting_hours.mp4 new file mode 100644 index 0000000..2bcdea0 Binary files /dev/null and b/video/visiting_hours.mp4 differ