Spaces:
Sleeping
Sleeping
test
Browse files- app.py +63 -4
- requirements.txt +9 -3
- static/.DS_Store +0 -0
- static/intents.json +0 -0
- static/style.css +223 -0
- templates/chat.html +410 -0
app.py
CHANGED
@@ -1,7 +1,66 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
2 |
|
3 |
app = Flask(__name__)
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import random
|
3 |
+
from fuzzywuzzy import process
|
4 |
+
from flask import Flask, request, render_template
|
5 |
+
import joblib
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
+
# Load intents.json
|
10 |
+
with open("static/intents.json", "r") as file:
|
11 |
+
intents = json.load(file)
|
12 |
+
|
13 |
+
import joblib
|
14 |
+
nlp = joblib.load("static/chatbot_model1.joblib")
|
15 |
+
|
16 |
+
# Extract all possible questions for fuzzy matching
|
17 |
+
all_questions = []
|
18 |
+
question_to_intent = {}
|
19 |
+
for intent in intents["intents"]:
|
20 |
+
for pattern in intent["patterns"]:
|
21 |
+
all_questions.append(pattern)
|
22 |
+
question_to_intent[pattern] = intent["tag"]
|
23 |
+
|
24 |
+
# Function to get intent using the trained model
|
25 |
+
def get_intent(text):
|
26 |
+
doc = nlp(text)
|
27 |
+
intent = max(doc.cats, key=doc.cats.get)
|
28 |
+
return intent, doc.cats[intent]
|
29 |
+
|
30 |
+
# Function for fuzzy matching
|
31 |
+
def fuzzy_match(text, questions, threshold=80):
|
32 |
+
match, score = process.extractOne(text, questions)
|
33 |
+
return match if score >= threshold else None
|
34 |
+
|
35 |
+
# Function to get chatbot response
|
36 |
+
def chatbot_response(user_input):
|
37 |
+
intent, confidence = get_intent(user_input)
|
38 |
+
|
39 |
+
if confidence > 0.75: # If spaCy model is confident
|
40 |
+
for intent_data in intents["intents"]:
|
41 |
+
if intent_data["tag"] == intent:
|
42 |
+
return random.choice(intent_data["responses"])
|
43 |
+
|
44 |
+
# Fallback to fuzzy matching
|
45 |
+
best_match = fuzzy_match(user_input, all_questions)
|
46 |
+
if best_match:
|
47 |
+
matched_intent = question_to_intent[best_match]
|
48 |
+
for intent_data in intents["intents"]:
|
49 |
+
if intent_data["tag"] == matched_intent:
|
50 |
+
return random.choice(intent_data["responses"])
|
51 |
+
|
52 |
+
return "Sorry, I didn't understand that. Can you rephrase?"
|
53 |
+
|
54 |
+
# Flask routes
|
55 |
+
@app.route("/")
|
56 |
+
def index():
|
57 |
+
return render_template("chat.html") # Make sure chat.html exists
|
58 |
+
|
59 |
+
@app.route("/get", methods=["POST"])
|
60 |
+
def chat():
|
61 |
+
msg = request.form["msg"]
|
62 |
+
response = chatbot_response(msg)
|
63 |
+
return response
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
app.run(debug=False)
|
requirements.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask==3.1.0
|
2 |
+
fuzzywuzzy==0.18.0
|
3 |
+
gunicorn==23.0.0
|
4 |
+
huggingface==0.0.1
|
5 |
+
huggingface-hub==0.28.1
|
6 |
+
joblib==1.4.2
|
7 |
+
requests==2.32.3
|
8 |
+
spacy==3.8.4
|
9 |
+
python-Levenshtein
|
static/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
static/intents.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
static/style.css
ADDED
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body,html{
|
2 |
+
height: 100%;
|
3 |
+
margin: 0;
|
4 |
+
background: rgb(44, 47, 59);
|
5 |
+
background: -webkit-linear-gradient(to right, rgb(40, 59, 34), rgb(54, 60, 70), rgb(32, 32, 43));
|
6 |
+
background: linear-gradient(to right, rgb(38, 51, 61), rgb(50, 55, 65), rgb(33, 33, 78));
|
7 |
+
}
|
8 |
+
|
9 |
+
.chat{
|
10 |
+
margin-top: auto;
|
11 |
+
margin-bottom: auto;
|
12 |
+
}
|
13 |
+
.card{
|
14 |
+
height: 600px;
|
15 |
+
border-radius: 15px !important;
|
16 |
+
background-color: rgba(0,0,0,0.4) !important;
|
17 |
+
}
|
18 |
+
.contacts_body{
|
19 |
+
padding: 0.75rem 0 !important;
|
20 |
+
overflow-y: auto;
|
21 |
+
white-space: nowrap;
|
22 |
+
}
|
23 |
+
.msg_card_body{
|
24 |
+
overflow-y: auto;
|
25 |
+
}
|
26 |
+
.card-header{
|
27 |
+
border-radius: 15px 15px 0 0 !important;
|
28 |
+
border-bottom: 0 !important;
|
29 |
+
}
|
30 |
+
.card-footer{
|
31 |
+
border-radius: 0 0 15px 15px !important;
|
32 |
+
border-top: 0 !important;
|
33 |
+
}
|
34 |
+
.container{
|
35 |
+
align-content: center;
|
36 |
+
}
|
37 |
+
.search{
|
38 |
+
border-radius: 15px 0 0 15px !important;
|
39 |
+
background-color: rgba(0,0,0,0.3) !important;
|
40 |
+
border:0 !important;
|
41 |
+
color:white !important;
|
42 |
+
}
|
43 |
+
.search:focus{
|
44 |
+
box-shadow:none !important;
|
45 |
+
outline:0px !important;
|
46 |
+
}
|
47 |
+
.type_msg{
|
48 |
+
background-color: rgba(0,0,0,0.3) !important;
|
49 |
+
border:0 !important;
|
50 |
+
color:white !important;
|
51 |
+
height: 60px !important;
|
52 |
+
overflow-y: auto;
|
53 |
+
}
|
54 |
+
.type_msg:focus{
|
55 |
+
box-shadow:none !important;
|
56 |
+
outline:0px !important;
|
57 |
+
}
|
58 |
+
.attach_btn{
|
59 |
+
border-radius: 15px 0 0 15px !important;
|
60 |
+
background-color: rgba(0,0,0,0.3) !important;
|
61 |
+
border:0 !important;
|
62 |
+
color: white !important;
|
63 |
+
cursor: pointer;
|
64 |
+
}
|
65 |
+
.send_btn{
|
66 |
+
border-radius: 0 15px 15px 0 !important;
|
67 |
+
background-color: rgba(0,0,0,0.3) !important;
|
68 |
+
border:0 !important;
|
69 |
+
color: white !important;
|
70 |
+
cursor: pointer;
|
71 |
+
}
|
72 |
+
.search_btn{
|
73 |
+
border-radius: 0 15px 15px 0 !important;
|
74 |
+
background-color: rgba(0,0,0,0.3) !important;
|
75 |
+
border:0 !important;
|
76 |
+
color: white !important;
|
77 |
+
cursor: pointer;
|
78 |
+
}
|
79 |
+
.contacts{
|
80 |
+
list-style: none;
|
81 |
+
padding: 0;
|
82 |
+
}
|
83 |
+
.contacts li{
|
84 |
+
width: 100% !important;
|
85 |
+
padding: 5px 10px;
|
86 |
+
margin-bottom: 15px !important;
|
87 |
+
}
|
88 |
+
.active{
|
89 |
+
background-color: rgba(0,0,0,0.3);
|
90 |
+
}
|
91 |
+
.user_img{
|
92 |
+
height: 70px;
|
93 |
+
width: 70px;
|
94 |
+
border:1.5px solid #f5f6fa;
|
95 |
+
|
96 |
+
}
|
97 |
+
.user_img_msg{
|
98 |
+
height: 40px;
|
99 |
+
width: 40px;
|
100 |
+
border:1.5px solid #f5f6fa;
|
101 |
+
|
102 |
+
}
|
103 |
+
.img_cont{
|
104 |
+
position: relative;
|
105 |
+
height: 70px;
|
106 |
+
width: 70px;
|
107 |
+
}
|
108 |
+
.img_cont_msg{
|
109 |
+
height: 40px;
|
110 |
+
width: 40px;
|
111 |
+
}
|
112 |
+
.online_icon{
|
113 |
+
position: absolute;
|
114 |
+
height: 15px;
|
115 |
+
width:15px;
|
116 |
+
background-color: #4cd137;
|
117 |
+
border-radius: 50%;
|
118 |
+
bottom: 0.2em;
|
119 |
+
right: 0.4em;
|
120 |
+
border:1.5px solid white;
|
121 |
+
}
|
122 |
+
.offline{
|
123 |
+
background-color: #c23616 !important;
|
124 |
+
}
|
125 |
+
.user_info{
|
126 |
+
margin-top: auto;
|
127 |
+
margin-bottom: auto;
|
128 |
+
margin-left: 15px;
|
129 |
+
}
|
130 |
+
.user_info span{
|
131 |
+
font-size: 20px;
|
132 |
+
color: white;
|
133 |
+
}
|
134 |
+
.user_info p{
|
135 |
+
font-size: 10px;
|
136 |
+
color: rgba(255,255,255,0.6);
|
137 |
+
}
|
138 |
+
.video_cam{
|
139 |
+
margin-left: 50px;
|
140 |
+
margin-top: 5px;
|
141 |
+
}
|
142 |
+
.video_cam span{
|
143 |
+
color: white;
|
144 |
+
font-size: 20px;
|
145 |
+
cursor: pointer;
|
146 |
+
margin-right: 20px;
|
147 |
+
}
|
148 |
+
.msg_cotainer{
|
149 |
+
margin-top: auto;
|
150 |
+
margin-bottom: auto;
|
151 |
+
margin-left: 10px;
|
152 |
+
border-radius: 25px;
|
153 |
+
background-color: rgb(82, 172, 255);
|
154 |
+
padding: 10px;
|
155 |
+
position: relative;
|
156 |
+
}
|
157 |
+
.msg_cotainer_send{
|
158 |
+
margin-top: auto;
|
159 |
+
margin-bottom: auto;
|
160 |
+
margin-right: 10px;
|
161 |
+
border-radius: 25px;
|
162 |
+
background-color: #58cc71;
|
163 |
+
padding: 10px;
|
164 |
+
position: relative;
|
165 |
+
}
|
166 |
+
.msg_time{
|
167 |
+
position: absolute;
|
168 |
+
left: 0;
|
169 |
+
bottom: -15px;
|
170 |
+
color: rgba(255,255,255,0.5);
|
171 |
+
font-size: 10px;
|
172 |
+
}
|
173 |
+
.msg_time_send{
|
174 |
+
position: absolute;
|
175 |
+
right:0;
|
176 |
+
bottom: -15px;
|
177 |
+
color: rgba(255,255,255,0.5);
|
178 |
+
font-size: 10px;
|
179 |
+
}
|
180 |
+
.msg_head{
|
181 |
+
position: relative;
|
182 |
+
}
|
183 |
+
#action_menu_btn{
|
184 |
+
position: absolute;
|
185 |
+
right: 10px;
|
186 |
+
top: 10px;
|
187 |
+
color: white;
|
188 |
+
cursor: pointer;
|
189 |
+
font-size: 20px;
|
190 |
+
}
|
191 |
+
.action_menu{
|
192 |
+
z-index: 1;
|
193 |
+
position: absolute;
|
194 |
+
padding: 15px 0;
|
195 |
+
background-color: rgba(0,0,0,0.5);
|
196 |
+
color: white;
|
197 |
+
border-radius: 15px;
|
198 |
+
top: 30px;
|
199 |
+
right: 15px;
|
200 |
+
display: none;
|
201 |
+
}
|
202 |
+
.action_menu ul{
|
203 |
+
list-style: none;
|
204 |
+
padding: 0;
|
205 |
+
margin: 0;
|
206 |
+
}
|
207 |
+
.action_menu ul li{
|
208 |
+
width: 100%;
|
209 |
+
padding: 10px 15px;
|
210 |
+
margin-bottom: 5px;
|
211 |
+
}
|
212 |
+
.action_menu ul li i{
|
213 |
+
padding-right: 10px;
|
214 |
+
}
|
215 |
+
.action_menu ul li:hover{
|
216 |
+
cursor: pointer;
|
217 |
+
background-color: rgba(0,0,0,0.2);
|
218 |
+
}
|
219 |
+
@media(max-width: 576px){
|
220 |
+
.contacts_card{
|
221 |
+
margin-bottom: 15px !important;
|
222 |
+
}
|
223 |
+
}
|
templates/chat.html
ADDED
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>JUIT AI Assist</title>
|
8 |
+
<link rel="shortcut icon" href="#" />
|
9 |
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
|
10 |
+
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
|
11 |
+
crossorigin="anonymous">
|
12 |
+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
|
13 |
+
integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU"
|
14 |
+
crossorigin="anonymous">
|
15 |
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
16 |
+
<script>
|
17 |
+
window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
|
18 |
+
</script>
|
19 |
+
<script defer src="/_vercel/insights/script.js"></script>
|
20 |
+
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" />
|
21 |
+
|
22 |
+
<style>
|
23 |
+
body, html {
|
24 |
+
height: 100%;
|
25 |
+
margin: 0;
|
26 |
+
background: rgb(44, 47, 59);
|
27 |
+
background: -webkit-linear-gradient(to right, rgb(40, 59, 34), rgb(54, 60, 70), rgb(32, 32, 43));
|
28 |
+
background: linear-gradient(to right, rgb(38, 51, 61), rgb(50, 55, 65), rgb(33, 33, 78));
|
29 |
+
}
|
30 |
+
|
31 |
+
.chat {
|
32 |
+
margin-top: auto;
|
33 |
+
margin-bottom: auto;
|
34 |
+
height: 80%;
|
35 |
+
}
|
36 |
+
|
37 |
+
.card {
|
38 |
+
height: calc(100% - 40px);
|
39 |
+
max-height: calc(100% - 40px);
|
40 |
+
overflow: hidden;
|
41 |
+
position: relative;
|
42 |
+
}
|
43 |
+
|
44 |
+
.msg_card_body {
|
45 |
+
overflow-y: auto;
|
46 |
+
max-height: calc(100% - 120px);
|
47 |
+
}
|
48 |
+
|
49 |
+
.predefined-text {
|
50 |
+
background-color: #1f2937;
|
51 |
+
color: #f3f4f6;
|
52 |
+
padding: 15px;
|
53 |
+
margin-bottom: 20px;
|
54 |
+
border-radius: 10px;
|
55 |
+
font-size: 18px;
|
56 |
+
text-align: center;
|
57 |
+
font-weight: bold;
|
58 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
59 |
+
}
|
60 |
+
|
61 |
+
.predictive-text {
|
62 |
+
position: absolute;
|
63 |
+
background-color: rgba(0, 0, 0, 0.7);
|
64 |
+
border: 1px solid #333;
|
65 |
+
border-radius: 10px;
|
66 |
+
padding: 5px;
|
67 |
+
z-index: 999;
|
68 |
+
cursor: pointer;
|
69 |
+
max-height: 150px;
|
70 |
+
overflow-y: auto;
|
71 |
+
width: calc(100% - 22px);
|
72 |
+
bottom: 65px;
|
73 |
+
left: 10px;
|
74 |
+
color: #fff;
|
75 |
+
}
|
76 |
+
|
77 |
+
.predictive-text p {
|
78 |
+
margin: 5px 0;
|
79 |
+
padding: 5px;
|
80 |
+
cursor: pointer;
|
81 |
+
transition: background-color 0.3s;
|
82 |
+
border-radius: 5px;
|
83 |
+
}
|
84 |
+
|
85 |
+
.predictive-text p:hover {
|
86 |
+
background-color: rgba(255, 255, 255, 0.2);
|
87 |
+
}
|
88 |
+
|
89 |
+
.predictive-text p:not(:last-child) {
|
90 |
+
border-bottom: 1px solid #555;
|
91 |
+
}
|
92 |
+
|
93 |
+
input[type="text"] {
|
94 |
+
white-space: normal;
|
95 |
+
overflow-wrap: break-word;
|
96 |
+
word-wrap: break-word;
|
97 |
+
width: 100%;
|
98 |
+
padding: 10px;
|
99 |
+
height: auto;
|
100 |
+
}
|
101 |
+
|
102 |
+
::placeholder {
|
103 |
+
white-space: normal;
|
104 |
+
overflow-wrap: break-word;
|
105 |
+
word-wrap: break-word;
|
106 |
+
}
|
107 |
+
</style>
|
108 |
+
|
109 |
+
</head>
|
110 |
+
|
111 |
+
<body>
|
112 |
+
<div class="container-fluid h-100">
|
113 |
+
<div class="row justify-content-center h-100">
|
114 |
+
<div class="col-md-8 col-xl-6 chat">
|
115 |
+
<div class="card">
|
116 |
+
<div class="card-header msg_head">
|
117 |
+
<div class="d-flex bd-highlight">
|
118 |
+
<div class="img_cont">
|
119 |
+
<img src="https://i.ibb.co/jRMcPVs/snjb.jpg" class="rounded-circle user_img">
|
120 |
+
<span class="online_icon"></span>
|
121 |
+
</div>
|
122 |
+
<div class="user_info">
|
123 |
+
<span>JUIT AI Assist</span>
|
124 |
+
<p>Explore College and Beyond: Ask Anything! 🎓</p>
|
125 |
+
<div class="predefined-text">
|
126 |
+
Use keywords instead of full sentences. For example, if you want to ask about placement, type 'placement' for the best answers.
|
127 |
+
</div>
|
128 |
+
</div>
|
129 |
+
</div>
|
130 |
+
</div>
|
131 |
+
|
132 |
+
<div id="messageFormeight" class="card-body msg_card_body">
|
133 |
+
<!-- Chat messages will be displayed here -->
|
134 |
+
</div>
|
135 |
+
<div class="card-footer" style="position: relative;">
|
136 |
+
<form id="messageArea" class="input-group">
|
137 |
+
<input type="text" id="text" name="msg" placeholder="Type your message..." autocomplete="off"
|
138 |
+
class="form-control type_msg" required />
|
139 |
+
<div class="input-group-append">
|
140 |
+
<button type="submit" id="send" class="input-group-text send_btn"><i
|
141 |
+
class="fas fa-location-arrow"></i></button>
|
142 |
+
</div>
|
143 |
+
</form>
|
144 |
+
<div class="predictive-text"></div>
|
145 |
+
</div>
|
146 |
+
</div>
|
147 |
+
</div>
|
148 |
+
</div>
|
149 |
+
</div>
|
150 |
+
|
151 |
+
<script>
|
152 |
+
$(document).ready(function() {
|
153 |
+
let chatHistory = []; // Stores the user's input history
|
154 |
+
let currentIndex = -1; // Tracks the current position in the history
|
155 |
+
|
156 |
+
// Handle predictive text
|
157 |
+
$("#text").on("input", function() {
|
158 |
+
var input = $(this).val().toLowerCase();
|
159 |
+
var predictions = getPredictiveText(input);
|
160 |
+
showPredictiveText(predictions);
|
161 |
+
});
|
162 |
+
|
163 |
+
$(document).on("click", ".predictive-text p", function() {
|
164 |
+
var text = $(this).text();
|
165 |
+
$("#text").val(text);
|
166 |
+
$(".predictive-text").hide();
|
167 |
+
});
|
168 |
+
|
169 |
+
function getPredictiveText(input) {
|
170 |
+
var predictions = [];
|
171 |
+
var patterns = {
|
172 |
+
"greeting": ["Hi", "Hey", "How are you", "what's up", "Is anyone there?", "Hello", "Good day"],
|
173 |
+
"name": ["what is your name", "name", "what's your name", "who are you", "what should I call you"],
|
174 |
+
"tour":["virtual tour",
|
175 |
+
"campus tour","juit tour",
|
176 |
+
"how to see the campus",
|
177 |
+
"online campus tour",
|
178 |
+
"can I see the campus virtually",
|
179 |
+
"how to access the virtual tour",
|
180 |
+
"virtual campus tour","university virtual tour",
|
181 |
+
"college virtual tour",
|
182 |
+
"campus walkthrough",
|
183 |
+
"campus 3D tour",
|
184 |
+
"campus view online",
|
185 |
+
"JUIT virtual tour","JUIT virtual trip",
|
186 |
+
"virtual visit to JUIT",
|
187 |
+
"how to explore campus online",
|
188 |
+
"tour of JUIT campus"],
|
189 |
+
"Chandigarh Shimla Information": ["Chandigarh Shimla", "chandigarh", "shimla", "kalka",
|
190 |
+
"location of JUIT",
|
191 |
+
"JUIT Waknaghat location",
|
192 |
+
"distance from Chandigarh to JUIT",
|
193 |
+
"distance from Shimla to JUIT",
|
194 |
+
"how to reach JUIT from Chandigarh",
|
195 |
+
"how to reach JUIT from Shimla","JUIT distance from Kalka",
|
196 |
+
"JUIT road map",
|
197 |
+
"JUIT location details",
|
198 |
+
"JUIT distance from Waknaghat",
|
199 |
+
"nearest railway station to JUIT",
|
200 |
+
"nearest bus station to JUIT",
|
201 |
+
"JUIT directions",
|
202 |
+
"how to go to JUIT from Chandigarh",
|
203 |
+
"how to go to JUIT from Shimla", "chandigarh to juit","Kalka to juit","shimla to juit",
|
204 |
+
"how to go to JUIT from kalka", "juit to chandigarh","juit to kalka","juit to shimla",
|
205 |
+
"transport to JUIT from Chandigarh",
|
206 |
+
"JUIT from Shimla distance",
|
207 |
+
"how to reach JUIT by road", "location","Juit location","location of juit",
|
208 |
+
"where is it located","where is juit", "where is the university",
|
209 |
+
"what is the location of the college","where is college"
|
210 |
+
],
|
211 |
+
"btech_admission": [ "what is the process of admission",
|
212 |
+
"what is the admission process",
|
213 |
+
"How to take admission in your college",
|
214 |
+
"What is the process for admission",
|
215 |
+
"admission", "btech admission", "bachelors admission",
|
216 |
+
"how to get admission","btech admission",
|
217 |
+
"admission process","admission","juit admission"],
|
218 |
+
|
219 |
+
"phd_admission":["PhD",
|
220 |
+
"PhD admission", "admission for PhD",
|
221 |
+
"PhD admission rules", "rules for admission for PhD",
|
222 |
+
"PhD admission eligibility", "PhD", "apply for PhD", "apply to PhD",
|
223 |
+
"PhD fellowship","fellowship for PhD", "PhD stipend","stipend for PhD",
|
224 |
+
"PhD eligibility", "admission PhD","Doctor of Philosophy",
|
225 |
+
"How can I apply for a PhD at JUIT?",
|
226 |
+
"What are the rules for PhD admission?",
|
227 |
+
"What is the eligibility for a PhD program?",
|
228 |
+
"Is there an entrance exam for PhD at JUIT?",
|
229 |
+
"What is the duration of the PhD program?","PhD duration",
|
230 |
+
"What is open defence in a PhD program?","PhD open defence",
|
231 |
+
"What are the classifications of PhD scholars?",
|
232 |
+
"Tell me about full-time PhD admission.",
|
233 |
+
"Can I pursue a part-time PhD at JUIT?",
|
234 |
+
"What is a sponsored research scholar?","part-time PhD","full-time PhD",
|
235 |
+
"Where can I find the PhD entrance exam syllabus?", "PhD admission process",
|
236 |
+
"PhD entrance exam",
|
237 |
+
"PhD eligibility",
|
238 |
+
"Apply for PhD",
|
239 |
+
"PhD program duration",
|
240 |
+
"What is the PhD fee structure?",
|
241 |
+
"How much is the PhD stipend?",
|
242 |
+
"Eligibility criteria for PhD",
|
243 |
+
"What is the format of the PhD entrance test?",
|
244 |
+
"Can I do a PhD part-time?",
|
245 |
+
"PhD rules", "PhD in data science",
|
246 |
+
"Admission for PhD", "PhD in data science admission",
|
247 |
+
"PhD in machine learning admission",
|
248 |
+
"PhD in computer science admission",
|
249 |
+
"PhD in civil engineering admission",
|
250 |
+
"PhD in information technology admission",
|
251 |
+
"PhD in electrical engineering admission",
|
252 |
+
"PhD in electronics admission",
|
253 |
+
"PhD in ECE admission",
|
254 |
+
"PhD in biotechnology admission",
|
255 |
+
"PhD in bioinformatics admission",
|
256 |
+
"What is the eligibility for PhD in data science?",
|
257 |
+
"How to apply for PhD in machine learning?",
|
258 |
+
"What is the process for PhD in computer science?",
|
259 |
+
"Eligibility for PhD in civil engineering",
|
260 |
+
"Requirements for PhD in IT",
|
261 |
+
"What is the PhD admission process for electrical engineering?",
|
262 |
+
"Can I apply for PhD in ECE at JUIT?",
|
263 |
+
"Is there a specialization in biotechnology for PhD?",
|
264 |
+
"Are there PhD programs for bioinformatics?",
|
265 |
+
"PhD in data science eligibility",
|
266 |
+
"PhD in machine learning eligibility",
|
267 |
+
"PhD in civil engineering rules",
|
268 |
+
"How to apply for PhD in electronics?",
|
269 |
+
"PhD in CSE at JUIT",
|
270 |
+
"PhD in computer science at JUIT",
|
271 |
+
"PhD in information technology at JUIT",
|
272 |
+
"What is the fee structure for PhD in data science?",
|
273 |
+
"PhD in ECE duration",
|
274 |
+
"Is there a stipend for PhD in electrical engineering?",
|
275 |
+
"Can I get a fellowship for PhD in biotechnology?",
|
276 |
+
"What is the admission deadline for PhD in bioinformatics?",
|
277 |
+
"Where can I find the syllabus for PhD in machine learning?",
|
278 |
+
"What is the format of the PhD entrance test for computer science?",
|
279 |
+
"Eligibility for PhD in electronics and communication",
|
280 |
+
"Duration of PhD in CSE at JUIT",
|
281 |
+
"Can I apply for a part-time PhD in civil engineering?",
|
282 |
+
"PhD program details for biotechnology",
|
283 |
+
"What are the research opportunities for PhD in data science?",
|
284 |
+
"Specializations for PhD in machine learning",
|
285 |
+
"What is the workload for PhD in computer science?",
|
286 |
+
"How to download the admission brochure for PhD in IT?",
|
287 |
+
"PhD in electrical engineering admission details",
|
288 |
+
"Research topics for PhD in bioinformatics",
|
289 |
+
"What are the classifications of PhD in electronics?",
|
290 |
+
"What are the steps for PhD admission?",
|
291 |
+
"PhD application form","PhD application",
|
292 |
+
"How can I apply for a PhD in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering) at JUIT?",
|
293 |
+
"What are the rules for PhD admission in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?",
|
294 |
+
"rules for PhD admission in (data science|machine learning|CSE|civil engineering|ml|ai|bt|bi|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?","PhD admission in (data science|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering) rules",
|
295 |
+
"What is the eligibility for a PhD in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?","eligibility for a PhD in (data science|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?",
|
296 |
+
"PhD in (data science|machine learning|CSE|civil engineering|computer science|IT|bt|bi|ml|ai|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering) eligibility",
|
297 |
+
"What is the duration of a PhD in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?","PhD in (data science|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)","duration of a PhD in (data science|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering) duration",
|
298 |
+
"What is the process for a PhD in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)","PhD in (data science|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)","process for a PhD in (data science|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering) process",
|
299 |
+
"PhD admission process in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)",
|
300 |
+
"PhD eligibility for (data science|machine learning|CSE|ml|bt|bi|ai|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)",
|
301 |
+
"Apply for PhD in (data science|machine learning|CSE|ml|ai|bt|bi|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)",
|
302 |
+
"Is there an entrance exam for a PhD in (data science|ml|ai|bt|bi|machine learning|CSE|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?",
|
303 |
+
"What is the syllabus for the PhD entrance exam in (data science|machine learning|CSE|ml|bt|bi|ai|civil engineering|computer science|IT|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering)?",
|
304 |
+
"PhD entrance exam in (data science|machine learning|CSE|civil engineering|computer science|bt|bi|IT|ml|ai|information technology|bioinformatics|biotechnology|artificial intelligence|ECE|electronics|electrical engineering) syllabus",
|
305 |
+
"Are international students eligible for PhD?",
|
306 |
+
"What is the process for PhD admission?",
|
307 |
+
"PhD program details","PhD program",
|
308 |
+
"What is the syllabus for the PhD entrance exam?","PhD entrance exam","PhD entrance exam syllabus",
|
309 |
+
"Do I need a master's degree for a PhD?",
|
310 |
+
"What is the selection process for PhD?","PhD election process","phd research",
|
311 |
+
"What is the research proposal format for PhD?",
|
312 |
+
"What are the deadlines for PhD admission?",
|
313 |
+
"How can I apply online for PhD?","phd apply","phd online apply","apply for phd","online apply for phd",
|
314 |
+
"Is there financial aid for PhD students?",
|
315 |
+
"Can I apply for a PhD without GATE/NET?",
|
316 |
+
"Where can I download the PhD guidelines?","PhD guidelines","guidelines for PhD",
|
317 |
+
"What are the PhD specializations offered?",
|
318 |
+
"PhD classifications at JUIT","PhD classifications","types of PhD","PhD types",
|
319 |
+
"How are PhD scholars evaluated?",
|
320 |
+
"Can I change my PhD supervisor?","PhD supervisor",
|
321 |
+
"What is the maximum duration for a PhD?","how much time to complete PhD", "maximum duration of PhD",
|
322 |
+
"Can I withdraw from the PhD program?", "PhD program withdraw","withdraw from PhD program",
|
323 |
+
"PhD attendance requirements","PhD attendance",
|
324 |
+
"PhD course work details","PhD course work","details of PhD course work",
|
325 |
+
"Is teaching mandatory for PhD scholars?","PhD scholars? teaching"]
|
326 |
+
|
327 |
+
|
328 |
+
|
329 |
+
};
|
330 |
+
|
331 |
+
for (var tag in patterns) {
|
332 |
+
patterns[tag].forEach(function(pattern) {
|
333 |
+
if (pattern.toLowerCase().startsWith(input) && !predictions.includes(pattern)) {
|
334 |
+
predictions.push(pattern);
|
335 |
+
}
|
336 |
+
});
|
337 |
+
}
|
338 |
+
return predictions;
|
339 |
+
}
|
340 |
+
|
341 |
+
function showPredictiveText(predictions) {
|
342 |
+
if (predictions.length > 0) {
|
343 |
+
var html = "";
|
344 |
+
predictions.forEach(function(prediction) {
|
345 |
+
html += "<p>" + prediction + "</p>";
|
346 |
+
});
|
347 |
+
$(".predictive-text").html(html).show();
|
348 |
+
} else {
|
349 |
+
$(".predictive-text").hide();
|
350 |
+
}
|
351 |
+
}
|
352 |
+
|
353 |
+
// Handle message submission and user input history
|
354 |
+
$("#messageArea").on("submit", function(event) {
|
355 |
+
$(".predictive-text").hide(); // Hide predictive suggestions
|
356 |
+
|
357 |
+
const date = new Date();
|
358 |
+
const hour = date.getHours().toString().padStart(2, '0');
|
359 |
+
const minute = date.getMinutes().toString().padStart(2, '0');
|
360 |
+
const str_time = hour + ":" + minute;
|
361 |
+
|
362 |
+
var rawText = $("#text").val();
|
363 |
+
chatHistory.push(rawText); // Store the user's message in history
|
364 |
+
currentIndex = chatHistory.length - 1; // Update the current index
|
365 |
+
|
366 |
+
var userHtml = '<div class="d-flex justify-content-end mb-4"><div class="msg_cotainer_send">' + rawText +
|
367 |
+
'<span class="msg_time_send">' + str_time + '</span></div><div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div></div>';
|
368 |
+
|
369 |
+
$("#text").val(""); // Clear the input field
|
370 |
+
$("#messageFormeight").append(userHtml); // Add the user message to the chat
|
371 |
+
|
372 |
+
// Handle up arrow key for cycling through messages
|
373 |
+
$(document).on("keydown", function(event) {
|
374 |
+
if (event.key === "ArrowUp") {
|
375 |
+
if (currentIndex > 0) {
|
376 |
+
currentIndex--; // Move to the previous message
|
377 |
+
$("#text").val(chatHistory[currentIndex]); // Update the input field with the previous message
|
378 |
+
}
|
379 |
+
}
|
380 |
+
});
|
381 |
+
|
382 |
+
// Send the message to the server via AJAX
|
383 |
+
$.ajax({
|
384 |
+
data: {
|
385 |
+
msg: rawText,
|
386 |
+
},
|
387 |
+
type: "POST",
|
388 |
+
url: "/get",
|
389 |
+
}).done(function(data) {
|
390 |
+
var lines = data.split("**");
|
391 |
+
var botHtml = '<div class="d-flex justify-content-start mb-4"><div class="img_cont_msg"><img src="https://i.ibb.co/jRMcPVs/snjb.jpg" class="rounded-circle user_img_msg"></div><div class="msg_cotainer">';
|
392 |
+
for (var i = 0; i < lines.length; i++) {
|
393 |
+
botHtml += '<div class="msg_cotainer">' + lines[i] + '</div>';
|
394 |
+
}
|
395 |
+
botHtml += '<span class="msg_time">' + str_time + '</span></div></div>';
|
396 |
+
$("#messageFormeight").append($.parseHTML(botHtml));
|
397 |
+
|
398 |
+
// Smooth scroll to the bottom of the chat
|
399 |
+
var container = $("#messageFormeight");
|
400 |
+
container.animate({ scrollTop: container.prop("scrollHeight") }, 500);
|
401 |
+
});
|
402 |
+
|
403 |
+
event.preventDefault(); // Prevent form submission
|
404 |
+
});
|
405 |
+
});
|
406 |
+
</script>
|
407 |
+
|
408 |
+
</body>
|
409 |
+
|
410 |
+
</html>
|