Nahiyan14 commited on
Commit
f9264b0
·
verified ·
1 Parent(s): 5a56851

Upload 8 files

Browse files
src/__init__.py ADDED
File without changes
src/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (147 Bytes). View file
 
src/__pycache__/helper.cpython-310.pyc ADDED
Binary file (1.08 kB). View file
 
src/__pycache__/prompt.cpython-310.pyc ADDED
Binary file (428 Bytes). View file
 
src/helper.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.document_loaders import PyPDFLoader, DirectoryLoader
2
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
3
+ from langchain.embeddings import HuggingFaceEmbeddings
4
+ from sentence_transformers import SentenceTransformer
5
+
6
+
7
+ #Extract Data From the PDF File
8
+ def load_pdf_file(data):
9
+ loader= DirectoryLoader(data,
10
+ glob="*.pdf",
11
+ loader_cls=PyPDFLoader)
12
+
13
+ documents=loader.load()
14
+
15
+ return documents
16
+
17
+
18
+
19
+ #Split the Data into Text Chunks
20
+ def text_split(extracted_data):
21
+ text_splitter=RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=20)
22
+ text_chunks=text_splitter.split_documents(extracted_data)
23
+ return text_chunks
24
+
25
+
26
+
27
+ #Download the Embeddings from HuggingFace
28
+ def download_hugging_face_embeddings():
29
+ embeddings=HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2') #this model return 384 dimensions
30
+ return embeddings
src/prompt.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ system_prompt = (
2
+ "You are an assistant for question-answering tasks. "
3
+ "Use the following pieces of retrieved context to answer "
4
+ "the question. If you don't know the answer, say that you "
5
+ "are not aware of this topic. Use three sentences maximum and keep the "
6
+ "answer concise."
7
+ "\n\n"
8
+ "{context}"
9
+ )
static/style.css ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* General Styles */
2
+ body, html {
3
+ height: 100%;
4
+ margin: 0;
5
+ background: linear-gradient(to right, #1e3c72, #2a5298);
6
+ font-family: 'Arial', sans-serif;
7
+ color: white;
8
+ }
9
+
10
+ /* Chat Container */
11
+ .chat-container {
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ }
17
+
18
+ /* Chat Card */
19
+ .chat-card {
20
+ width: 40%;
21
+ max-width: 600px;
22
+ background: rgba(255, 255, 255, 0.1);
23
+ border-radius: 15px;
24
+ box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
25
+ overflow: hidden;
26
+ }
27
+
28
+ /* Chat Header */
29
+ .chat-header {
30
+ background: rgba(255, 255, 255, 0.2);
31
+ padding: 15px;
32
+ display: flex;
33
+ align-items: center;
34
+ border-bottom: 1px solid rgba(255, 255, 255, 0.3);
35
+ }
36
+
37
+ .chat-header img {
38
+ width: 50px;
39
+ height: 50px;
40
+ border-radius: 50%;
41
+ margin-right: 10px;
42
+ }
43
+
44
+ .chat-header h2 {
45
+ font-size: 18px;
46
+ margin: 0;
47
+ }
48
+
49
+ /* Chat Body */
50
+ .chat-body {
51
+ padding: 15px;
52
+ height: 400px;
53
+ overflow-y: auto;
54
+ }
55
+
56
+ /* Messages */
57
+ .message {
58
+ display: flex;
59
+ align-items: center;
60
+ margin-bottom: 15px;
61
+ }
62
+
63
+ .user-message {
64
+ justify-content: flex-end;
65
+ }
66
+
67
+ .bot-message {
68
+ justify-content: flex-start;
69
+ }
70
+
71
+ .message-text {
72
+ max-width: 70%;
73
+ padding: 10px 15px;
74
+ border-radius: 20px;
75
+ font-size: 14px;
76
+ }
77
+
78
+ .user-message .message-text {
79
+ background: #58cc71;
80
+ color: white;
81
+ border-bottom-right-radius: 0;
82
+ }
83
+
84
+ .bot-message .message-text {
85
+ background: #0078ff;
86
+ color: white;
87
+ border-bottom-left-radius: 0;
88
+ }
89
+
90
+ /* Chat Footer */
91
+ .chat-footer {
92
+ display: flex;
93
+ padding: 15px;
94
+ background: rgba(255, 255, 255, 0.2);
95
+ border-top: 1px solid rgba(255, 255, 255, 0.3);
96
+ }
97
+
98
+ .chat-footer input {
99
+ flex: 1;
100
+ padding: 10px;
101
+ border: none;
102
+ border-radius: 20px;
103
+ margin-right: 10px;
104
+ font-size: 14px;
105
+ }
106
+
107
+ .chat-footer button {
108
+ background: #0078ff;
109
+ color: white;
110
+ border: none;
111
+ padding: 10px 15px;
112
+ border-radius: 20px;
113
+ cursor: pointer;
114
+ transition: background 0.3s;
115
+ }
116
+
117
+ .chat-footer button:hover {
118
+ background: #0056b3;
119
+ }
templates/chat.html ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Chatbot</title>
7
+ <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
8
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
9
+ </head>
10
+ <body>
11
+
12
+ <div class="chat-container">
13
+ <div class="chat-card">
14
+
15
+ <!-- Chat Header -->
16
+ <div class="chat-header">
17
+ <img src="https://online.flipbuilder.com/clinical-library/vxes/files/shot.png" alt="Bot">
18
+ <h2>USMLE Step 1(First Aid) Expert</h2>
19
+ </div>
20
+
21
+ <!-- Chat Body -->
22
+ <div id="chat-body" class="chat-body">
23
+ <!-- Messages will be displayed here -->
24
+ </div>
25
+
26
+ <!-- Chat Footer -->
27
+ <div class="chat-footer">
28
+ <form id="chat-form">
29
+ <input type="text" id="user-input" placeholder="Type your message..." autocomplete="off" required>
30
+ <button type="submit"><i class="fas fa-paper-plane"></i> Send</button>
31
+ </form>
32
+ </div>
33
+
34
+ </div>
35
+ </div>
36
+
37
+ <script>
38
+ $(document).ready(function () {
39
+ $("#chat-form").on("submit", function (event) {
40
+ event.preventDefault();
41
+
42
+ const userText = $("#user-input").val();
43
+ const timestamp = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
44
+
45
+ if (userText.trim() !== "") {
46
+ $("#chat-body").append(`
47
+ <div class="message user-message">
48
+ <div class="message-text">${userText} <span class="timestamp">${timestamp}</span></div>
49
+ </div>
50
+ `);
51
+ $("#user-input").val("");
52
+
53
+ $.ajax({
54
+ type: "POST",
55
+ url: "/get",
56
+ data: { msg: userText },
57
+ }).done(function (botResponse) {
58
+ $("#chat-body").append(`
59
+ <div class="message bot-message">
60
+ <div class="message-text">${botResponse} <span class="timestamp">${timestamp}</span></div>
61
+ </div>
62
+ `);
63
+ });
64
+ }
65
+ });
66
+ });
67
+ </script>
68
+
69
+ </body>
70
+ </html>