Spaces:
Running
Running
fix js issue
Browse files- app.py +3 -3
- static/script.js +23 -15
- static/styles.css +5 -4
- templates/chat.html +1 -1
- templates/index.html +0 -13
app.py
CHANGED
@@ -45,7 +45,7 @@ except:
|
|
45 |
# connect to index
|
46 |
pinecone_index = pc.Index(index_name)
|
47 |
|
48 |
-
bm25 = BM25Encoder().load("bm25_traveler_website.json")
|
49 |
|
50 |
embed_model = HuggingFaceEmbeddings(model_name="Alibaba-NLP/gte-large-en-v1.5", model_kwargs={"trust_remote_code":True})
|
51 |
|
@@ -157,9 +157,9 @@ def handle_message(data):
|
|
157 |
):
|
158 |
emit('response', chunk, room=request.sid)
|
159 |
|
160 |
-
app.route("/")
|
161 |
def index_view():
|
162 |
-
render_template('chat.html')
|
163 |
|
164 |
if __name__ == '__main__':
|
165 |
socketio.run(app, debug=True)
|
|
|
45 |
# connect to index
|
46 |
pinecone_index = pc.Index(index_name)
|
47 |
|
48 |
+
bm25 = BM25Encoder().load("./bm25_traveler_website.json")
|
49 |
|
50 |
embed_model = HuggingFaceEmbeddings(model_name="Alibaba-NLP/gte-large-en-v1.5", model_kwargs={"trust_remote_code":True})
|
51 |
|
|
|
157 |
):
|
158 |
emit('response', chunk, room=request.sid)
|
159 |
|
160 |
+
@app.route("/")
|
161 |
def index_view():
|
162 |
+
return render_template('chat.html')
|
163 |
|
164 |
if __name__ == '__main__':
|
165 |
socketio.run(app, debug=True)
|
static/script.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
const socket = io.connect(
|
2 |
|
3 |
const chatBox = document.getElementById('chat-box');
|
4 |
const chatInput = document.getElementById('chat-input');
|
@@ -7,32 +7,40 @@ var converter = new showdown.Converter();
|
|
7 |
var response="";
|
8 |
|
9 |
function appendMessage(message, sender) {
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
if(
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
|
|
19 |
const messageElement = document.createElement('div');
|
20 |
messageElement.classList.add('chat-message', sender);
|
21 |
messageElement.innerHTML = `<span>${message}</span>`;
|
22 |
-
|
23 |
-
chatBox.append(messageElement);
|
24 |
-
}else{
|
25 |
-
chatBox.prepend(messageElement);
|
26 |
-
}
|
27 |
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
|
|
|
|
28 |
}
|
|
|
29 |
}
|
30 |
|
31 |
sendButton.addEventListener('click', () => {
|
32 |
const message = chatInput.value.trim();
|
33 |
if (message) {
|
34 |
appendMessage(message, 'user');
|
35 |
-
document.getElementById("loader").classList.remove('hidden');
|
36 |
socket.emit('message', { question: message, session_id: 'abc123' });
|
37 |
chatInput.value = '';
|
38 |
response = "";
|
|
|
1 |
+
const socket = io.connect(document.baseURI);
|
2 |
|
3 |
const chatBox = document.getElementById('chat-box');
|
4 |
const chatInput = document.getElementById('chat-input');
|
|
|
7 |
var response="";
|
8 |
|
9 |
function appendMessage(message, sender) {
|
10 |
+
if(sender == "bot"){
|
11 |
+
response += message;
|
12 |
+
message = converter.makeHtml(response);
|
13 |
+
|
14 |
+
loader_ele = document.getElementById("loader");
|
15 |
+
|
16 |
+
if(!loader_ele.classList.contains("hidden")){
|
17 |
+
loader_ele.classList.add('hidden');
|
18 |
+
const messageElement = document.createElement('div');
|
19 |
+
messageElement.classList.add('chat-message', sender);
|
20 |
+
messageElement.innerHTML = `<span>${message}</span>`;
|
21 |
+
chatBox.append(messageElement);
|
22 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
23 |
+
}else{
|
24 |
+
last_message_ele = chatBox.lastElementChild.lastChild;
|
25 |
+
last_message_ele.innerHTML = message;
|
26 |
}
|
27 |
+
}else{
|
28 |
const messageElement = document.createElement('div');
|
29 |
messageElement.classList.add('chat-message', sender);
|
30 |
messageElement.innerHTML = `<span>${message}</span>`;
|
31 |
+
chatBox.prepend(messageElement);
|
|
|
|
|
|
|
|
|
32 |
chatBox.scrollTop = chatBox.scrollHeight;
|
33 |
+
setTimeout(() => {
|
34 |
+
document.getElementById("loader").classList.remove('hidden');
|
35 |
+
}, 500);
|
36 |
}
|
37 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
38 |
}
|
39 |
|
40 |
sendButton.addEventListener('click', () => {
|
41 |
const message = chatInput.value.trim();
|
42 |
if (message) {
|
43 |
appendMessage(message, 'user');
|
|
|
44 |
socket.emit('message', { question: message, session_id: 'abc123' });
|
45 |
chatInput.value = '';
|
46 |
response = "";
|
static/styles.css
CHANGED
@@ -4,6 +4,7 @@ body {
|
|
4 |
margin: 0;
|
5 |
padding: 0;
|
6 |
display: flex;
|
|
|
7 |
justify-content: center;
|
8 |
align-items: center;
|
9 |
height: 100vh;
|
@@ -42,7 +43,7 @@ body {
|
|
42 |
background-color: #007bff;
|
43 |
color: #fff;
|
44 |
padding: 10px;
|
45 |
-
border-radius:
|
46 |
display: inline-block;
|
47 |
max-width: 70%;
|
48 |
}
|
@@ -50,8 +51,8 @@ body {
|
|
50 |
.chat-message.bot span {
|
51 |
background-color: #e0e0e0;
|
52 |
color: #333;
|
53 |
-
padding: 10px;
|
54 |
-
border-radius:
|
55 |
display: inline-block;
|
56 |
max-width: 70%;
|
57 |
}
|
@@ -89,7 +90,7 @@ body {
|
|
89 |
.dot-loader {
|
90 |
background-color: #e0e0e0;
|
91 |
color: #333;
|
92 |
-
padding:
|
93 |
border-radius: 8px;
|
94 |
width: fit-content;
|
95 |
display: flex;
|
|
|
4 |
margin: 0;
|
5 |
padding: 0;
|
6 |
display: flex;
|
7 |
+
flex-direction: column;
|
8 |
justify-content: center;
|
9 |
align-items: center;
|
10 |
height: 100vh;
|
|
|
43 |
background-color: #007bff;
|
44 |
color: #fff;
|
45 |
padding: 10px;
|
46 |
+
border-radius: 12px;
|
47 |
display: inline-block;
|
48 |
max-width: 70%;
|
49 |
}
|
|
|
51 |
.chat-message.bot span {
|
52 |
background-color: #e0e0e0;
|
53 |
color: #333;
|
54 |
+
padding: 6px 10px;
|
55 |
+
border-radius: 12px;
|
56 |
display: inline-block;
|
57 |
max-width: 70%;
|
58 |
}
|
|
|
90 |
.dot-loader {
|
91 |
background-color: #e0e0e0;
|
92 |
color: #333;
|
93 |
+
padding: 15px;
|
94 |
border-radius: 8px;
|
95 |
width: fit-content;
|
96 |
display: flex;
|
templates/chat.html
CHANGED
@@ -7,11 +7,11 @@
|
|
7 |
<link rel="stylesheet" href="../static/styles.css">
|
8 |
</head>
|
9 |
<body>
|
|
|
10 |
<div class="chat-container">
|
11 |
<div class="chat-box" id="chat-box">
|
12 |
|
13 |
|
14 |
-
<!-- Dot Loader element -->
|
15 |
<div id="loader" class="dot-loader hidden">
|
16 |
<div></div>
|
17 |
<div></div>
|
|
|
7 |
<link rel="stylesheet" href="../static/styles.css">
|
8 |
</head>
|
9 |
<body>
|
10 |
+
<h3>This is a RAG application over the website <a href="https://omkar0896.pythonanywhere.com/">https://omkar0896.pythonanywhere.com/</a></h3>
|
11 |
<div class="chat-container">
|
12 |
<div class="chat-box" id="chat-box">
|
13 |
|
14 |
|
|
|
15 |
<div id="loader" class="dot-loader hidden">
|
16 |
<div></div>
|
17 |
<div></div>
|
templates/index.html
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<!-- templates/home.html -->
|
2 |
-
<!DOCTYPE html>
|
3 |
-
<html lang="en">
|
4 |
-
<head>
|
5 |
-
<meta charset="UTF-8">
|
6 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
-
<title>Home</title>
|
8 |
-
</head>
|
9 |
-
<body>
|
10 |
-
<h1>Welcome to the Flask Chat App</h1>
|
11 |
-
<p><a href="/chat">Go to Chat</a></p>
|
12 |
-
</body>
|
13 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|