Spaces:
Sleeping
Sleeping
Ritesh Thawkar
commited on
Commit
·
46de9df
1
Parent(s):
24e37bf
made chat response list styled
Browse files- .gitignore +2 -1
- app.py +22 -12
- templates/chat.html +49 -52
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
.env
|
|
|
|
1 |
+
.env
|
2 |
+
.adafsa-env
|
app.py
CHANGED
@@ -59,7 +59,7 @@ combined_vectorstore = excel_vectorstore
|
|
59 |
|
60 |
with open('combined_recursive_keyword_retriever.pkl', 'rb') as f:
|
61 |
combined_keyword_retriever = pickle.load(f)
|
62 |
-
combined_keyword_retriever.k = 1000
|
63 |
|
64 |
semantic_retriever = combined_vectorstore.as_retriever(search_type="mmr", search_kwargs={"k": 100})
|
65 |
|
@@ -76,23 +76,33 @@ compression_retriever = ContextualCompressionRetriever(
|
|
76 |
)
|
77 |
|
78 |
template = """
|
79 |
-
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
Generate responses in Arabic. Format any English words and numbers appropriately for clarity.
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
Provide detailed yet concise answers, covering all important aspects.
|
91 |
-
Remember, responding outside the CONTEXT may lead to the termination of the interaction.
|
92 |
CONTEXT: {context}
|
93 |
Query: {question}
|
94 |
-
|
95 |
-
After generating your response, ensure proper formatting and text direction of Arabic and English words/numbers. Return only the AI-generated answer.
|
96 |
"""
|
97 |
|
98 |
prompt = ChatPromptTemplate.from_template(template)
|
|
|
59 |
|
60 |
with open('combined_recursive_keyword_retriever.pkl', 'rb') as f:
|
61 |
combined_keyword_retriever = pickle.load(f)
|
62 |
+
# combined_keyword_retriever.k = 1000
|
63 |
|
64 |
semantic_retriever = combined_vectorstore.as_retriever(search_type="mmr", search_kwargs={"k": 100})
|
65 |
|
|
|
76 |
)
|
77 |
|
78 |
template = """
|
79 |
+
You are an Arabic AI Assistant focused on providing clear, detailed responses in HTML format with appropriate direction for Arabic language (right-to-left).
|
80 |
|
81 |
+
- Always answer truthfully. If the user query is irrelevant to the provided CONTEXT, respond by stating the reason.
|
82 |
+
- For general questions like greetings, reply with formal Arabic greetings.
|
83 |
+
- Generate responses in Arabic, and format any English words and numbers appropriately for clarity.
|
|
|
84 |
|
85 |
+
Response Formatting Guidelines:
|
86 |
|
87 |
+
- All responses must be generated in HTML and wrapped inside a <div dir="rtl"> tag.
|
88 |
+
- Utilize proper HTML tags for structuring the response:
|
89 |
+
- Use <p> for paragraphs.
|
90 |
+
- Apply <strong> for bold texts.
|
91 |
+
- Organize content with ordered (<ol>) or unordered (<ul>) lists as needed.
|
92 |
+
- Include line breaks (<br>) where appropriate for readability.
|
93 |
+
- Wrap all English words/numbers or sentences in a <span dir="ltr"> tag to maintain left-to-right directionality.
|
94 |
+
- Numbers with decimal values should be rounded off to two decimal places.
|
95 |
+
- Follow right-to-left language rules (dir="rtl"), ensuring Arabic text is properly aligned.
|
96 |
+
|
97 |
+
Additional Instructions:
|
98 |
+
|
99 |
+
- Provide detailed yet concise answers, covering all important aspects.
|
100 |
+
- Ensure proper HTML formatting is applied to the entire response for clarity and structure.
|
101 |
+
- Only return the AI-generated answer in HTML format.
|
102 |
+
- Responding outside the provided CONTEXT may result in the termination of the interaction.
|
103 |
|
|
|
|
|
104 |
CONTEXT: {context}
|
105 |
Query: {question}
|
|
|
|
|
106 |
"""
|
107 |
|
108 |
prompt = ChatPromptTemplate.from_template(template)
|
templates/chat.html
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html lang="
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
@@ -15,17 +15,17 @@
|
|
15 |
<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
|
16 |
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
|
17 |
|
|
|
|
|
|
|
18 |
<script src="https://cdn.tailwindcss.com"></script>
|
19 |
|
20 |
<style>
|
21 |
|
22 |
-
// <uniquifier>: Use a unique and descriptive class name
|
23 |
-
// <weight>: Use a value from 300 to 900
|
24 |
-
|
25 |
*:lang(ar-AR){
|
26 |
font-family: "Rubik", sans-serif;
|
27 |
font-optical-sizing: auto;
|
28 |
-
font-
|
29 |
}
|
30 |
|
31 |
.main-chat-container{
|
@@ -46,24 +46,10 @@
|
|
46 |
font-family: "DM Sans", sans-serif;
|
47 |
}
|
48 |
|
49 |
-
/* @media(max-width: 800px){
|
50 |
-
.chat-container-wrapper{
|
51 |
-
width: calc(100% - 30px);
|
52 |
-
margin: auto;
|
53 |
-
}
|
54 |
-
} */
|
55 |
-
|
56 |
.chat-container-wrapper * {
|
57 |
font-family: "DM Sans", sans-serif;
|
58 |
}
|
59 |
|
60 |
-
/* .chat-container-wrapper .chatbot-header{
|
61 |
-
display: flex;
|
62 |
-
flex-direction: row;
|
63 |
-
align-items: center;
|
64 |
-
justify-content: space-between;
|
65 |
-
} */
|
66 |
-
|
67 |
.chat-container-wrapper a{
|
68 |
color: rgb(11, 172, 235);
|
69 |
text-decoration:underline;
|
@@ -78,29 +64,29 @@
|
|
78 |
|
79 |
/* Hide scrollbar for Chrome, Safari and Opera */
|
80 |
.styled-scrolllbar::-webkit-scrollbar {
|
81 |
-
|
82 |
}
|
83 |
|
84 |
/* Hide scrollbar for IE, Edge and Firefox */
|
85 |
::-webkit-scrollbar {
|
86 |
-
|
87 |
-
|
88 |
}
|
89 |
|
90 |
/* Track */
|
91 |
::-webkit-scrollbar-track {
|
92 |
-
|
93 |
}
|
94 |
|
95 |
/* Handle */
|
96 |
::-webkit-scrollbar-thumb {
|
97 |
-
|
98 |
-
|
99 |
}
|
100 |
|
101 |
/* Handle on hover */
|
102 |
::-webkit-scrollbar-thumb:hover {
|
103 |
-
|
104 |
}
|
105 |
|
106 |
/* Hide scrollbar for Chrome, Safari and Opera */
|
@@ -115,7 +101,7 @@
|
|
115 |
}
|
116 |
|
117 |
.question-item:hover{
|
118 |
-
|
119 |
}
|
120 |
|
121 |
.sendbtn{
|
@@ -138,17 +124,13 @@
|
|
138 |
pointer-events: none;
|
139 |
}
|
140 |
|
141 |
-
/* div[contenteditable]:focus:empty:before {
|
142 |
-
content: 'Start typing';
|
143 |
-
} */
|
144 |
-
/* HTML: <div class="loader"></div> */
|
145 |
-
/* HTML: <div class="loader"></div> */
|
146 |
.chat-loader {
|
147 |
display: flex;
|
148 |
align-items: center;
|
149 |
gap: 6px;
|
150 |
padding: 8px 10px;
|
151 |
}
|
|
|
152 |
.chat-loader .dot {
|
153 |
width: 8px;
|
154 |
aspect-ratio: 1;
|
@@ -156,19 +138,24 @@
|
|
156 |
background-color: gray;
|
157 |
animation: l5 0.6s ease-in-out infinite;
|
158 |
}
|
|
|
159 |
.chat-loader .dot:nth-child(1){
|
160 |
animation-delay: 0s;
|
161 |
}
|
|
|
162 |
.chat-loader .dot:nth-child(2){
|
163 |
animation-delay: 0.2s;
|
164 |
}
|
|
|
165 |
.chat-loader .dot:nth-child(3){
|
166 |
animation-delay: 0.3s;
|
167 |
}
|
|
|
168 |
.message-content *{
|
169 |
width: 100%;
|
170 |
-
font-size:
|
171 |
}
|
|
|
172 |
.neumorphic-box-shadow{
|
173 |
border-radius: 50px;
|
174 |
background: #e0e0e0;
|
@@ -207,6 +194,7 @@
|
|
207 |
.bg-special-secondary{
|
208 |
background-color: rgb(230, 230, 230);
|
209 |
}
|
|
|
210 |
.message-content *:not(i){
|
211 |
font-family: "DM Sans", sans-serif;
|
212 |
}
|
@@ -215,37 +203,49 @@
|
|
215 |
color: black;
|
216 |
font-weight: bold;
|
217 |
}
|
|
|
218 |
.message-content h3:not(:first-of-type){
|
219 |
margin: 18px 0px 10px 0px;
|
220 |
color: black;
|
221 |
}
|
|
|
222 |
.message-content h4{
|
223 |
margin: 15px 0px 8px 0px;
|
224 |
}
|
|
|
225 |
.message-content h5, .message-content h6{
|
226 |
margin: 12px 0px 6px 0px;
|
227 |
}
|
|
|
228 |
.message-content ol, .message-content ul{
|
229 |
margin: 18px 0px;
|
230 |
-
list-style
|
|
|
|
|
231 |
}
|
|
|
232 |
.message-content ol li, .message-content ul li{
|
233 |
margin: 12px 0px ;
|
234 |
}
|
235 |
-
|
|
|
236 |
margin-bottom: 18px;
|
237 |
text-wrap: pretty;
|
238 |
}
|
|
|
239 |
.message-content a{
|
240 |
text-wrap: pretty;
|
241 |
}
|
|
|
242 |
.loading-text{
|
243 |
position: relative;
|
244 |
}
|
|
|
245 |
.loading-text::after{
|
246 |
content: '....';
|
247 |
animation: loading-text-animation 1s infinite;
|
248 |
}
|
|
|
249 |
@keyframes loading-text-animation {
|
250 |
0%{
|
251 |
content: ''
|
@@ -277,6 +277,12 @@
|
|
277 |
direction: ltr;
|
278 |
unicode-bidi: embed;
|
279 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
</style>
|
281 |
|
282 |
|
@@ -303,7 +309,7 @@
|
|
303 |
<hr>
|
304 |
|
305 |
|
306 |
-
<div class="relative chat-container w-full mx-auto hide-scrolllbar rounded-xl mb-20 flex flex-col
|
307 |
<div class="start-block load-chat-block w-full flex-grow flex flex-col items-center justify-center bg-white z-10">
|
308 |
<div class="w-full flex-grow flex flex-col items-center justify-center y-4 text-center">
|
309 |
<img src="./static/bg-image.jpg" class="w-1/2" alt="adafsa-logo">
|
@@ -379,7 +385,6 @@
|
|
379 |
</div>
|
380 |
</div>
|
381 |
</div>
|
382 |
-
|
383 |
</div>
|
384 |
|
385 |
<div class="absolute w-full h-full top-0 left-0 z-0 flex items-center justify-center">
|
@@ -408,7 +413,7 @@
|
|
408 |
<script>
|
409 |
|
410 |
// Initialize Socket.IO client
|
411 |
-
var socket = io.connect('
|
412 |
transports: ['websocket']
|
413 |
});
|
414 |
|
@@ -431,7 +436,7 @@
|
|
431 |
const isRTL = true;
|
432 |
$(".chat-container").append(
|
433 |
`
|
434 |
-
<div class="chat-block load-chat-block w-full flex flex-row-reverse items-start justify-end bg-secondary p-5 rounded-2xl rtl z-10 bg-
|
435 |
<div class="flex items-center order-2" >
|
436 |
<span class="bg-white" style="width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50px; padding: 5px; border: 2px solid #c2c2c2;">
|
437 |
<svg fill="#000000" width="36px" height="36px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M21.928 11.607c-.202-.488-.635-.605-.928-.633V8c0-1.103-.897-2-2-2h-6V4.61c.305-.274.5-.668.5-1.11a1.5 1.5 0 0 0-3 0c0 .442.195.836.5 1.11V6H5c-1.103 0-2 .897-2 2v2.997l-.082.006A1 1 0 0 0 1.99 12v2a1 1 0 0 0 1 1H3v5c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5a1 1 0 0 0 1-1v-1.938a1.006 1.006 0 0 0-.072-.455zM5 20V8h14l.001 3.996L19 12v2l.001.005.001 5.995H5z"></path><ellipse cx="8.5" cy="12" rx="1.5" ry="2"></ellipse><ellipse cx="15.5" cy="12" rx="1.5" ry="2"></ellipse><path d="M8 16h8v2H8z"></path></g></svg>
|
@@ -464,7 +469,7 @@
|
|
464 |
formatted_question = converter.makeHtml(formatted_question);
|
465 |
|
466 |
$(".chat-container").append(`
|
467 |
-
<div class="chat-block question-block w-full flex flex-row-reverse items-start justify-end p-5 z-10 rounded-2xl bg-
|
468 |
<div class="flex items-center order-2 bg-white rounded-full">
|
469 |
<span style="width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50px; padding: 3px; border: 2px solid #c2c2c2;">
|
470 |
<svg fill="#000000" width="36px" height="36px" viewBox="0 0 256 256" id="Flat" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M128,76a44,44,0,1,1-44,44A43.99983,43.99983,0,0,1,128,76Zm48-12h16V80a8,8,0,0,0,16,0V64h16a8,8,0,0,0,0-16H208V32a8,8,0,0,0-16,0V48H176a8,8,0,0,0,0,16Zm45.56006,40.95605a8.00039,8.00039,0,0,0-6.64893,9.15381A89.00044,89.00044,0,0,1,216,128a87.63672,87.63672,0,0,1-22.24182,58.41016,79.7044,79.7044,0,0,0-24.431-22.97461,59.83641,59.83641,0,0,1-82.6543,0A79.70345,79.70345,0,0,0,62.2417,186.41016,87.9498,87.9498,0,0,1,128,40a89.02966,89.02966,0,0,1,13.89062,1.08887,7.99994,7.99994,0,1,0,2.50391-15.80274A104.0826,104.0826,0,0,0,24,128a103.74716,103.74716,0,0,0,33.81934,76.68066,7.94507,7.94507,0,0,0,1.32629,1.18946,103.784,103.784,0,0,0,137.71252-.00293,7.94633,7.94633,0,0,0,1.31678-1.18115A103.74751,103.74751,0,0,0,232,128a105.04749,105.04749,0,0,0-1.28613-16.39453A7.99752,7.99752,0,0,0,221.56006,104.95605Z"></path> </g></svg>
|
@@ -503,28 +508,26 @@
|
|
503 |
function appendAnswer(answer) {
|
504 |
let lastElement = $(".chat-container .chat-block:last-child");
|
505 |
|
506 |
-
const englishRegex = /[
|
507 |
|
508 |
// Wrap English text and numbers in <span dir="ltr">
|
509 |
formatted_answer = answer.replace(englishRegex, function(match) {
|
510 |
return `<span class="special-span px-1" dir="ltr">${match}</span>`;
|
511 |
});
|
512 |
|
513 |
-
formatted_answer = converter.makeHtml(formatted_answer);
|
514 |
-
|
515 |
if (lastElement.hasClass("response-block")) {
|
516 |
$(".chat-container .chat-block:last-child").find(".message-content").html(formatted_answer);
|
517 |
} else {
|
518 |
lastElement.remove();
|
519 |
$(".chat-container").append(`
|
520 |
-
<div class="chat-block response-block w-full flex flex-row-reverse items-start justify-end bg-secondary p-5 rounded-2xl rtl z-10 bg-
|
521 |
<div class="flex items-center order-2" >
|
522 |
<span class="bg-white" style="width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50px; padding: 5px; border: 2px solid #c2c2c2;">
|
523 |
<svg fill="#000000" width="36px" height="36px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M21.928 11.607c-.202-.488-.635-.605-.928-.633V8c0-1.103-.897-2-2-2h-6V4.61c.305-.274.5-.668.5-1.11a1.5 1.5 0 0 0-3 0c0 .442.195.836.5 1.11V6H5c-1.103 0-2 .897-2 2v2.997l-.082.006A1 1 0 0 0 1.99 12v2a1 1 0 0 0 1 1H3v5c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5a1 1 0 0 0 1-1v-1.938a1.006 1.006 0 0 0-.072-.455zM5 20V8h14l.001 3.996L19 12v2l.001.005.001 5.995H5z"></path><ellipse cx="8.5" cy="12" rx="1.5" ry="2"></ellipse><ellipse cx="15.5" cy="12" rx="1.5" ry="2"></ellipse><path d="M8 16h8v2H8z"></path></g></svg>
|
524 |
</span>
|
525 |
</div>
|
526 |
<div class="px-3 py-1">
|
527 |
-
<div class="message-content pr-2" style="width: 100%; height: 100%; margin: auto;
|
528 |
${formatted_answer}
|
529 |
</div>
|
530 |
</div>
|
@@ -583,19 +586,13 @@
|
|
583 |
console.error("Connection error:", error);
|
584 |
appendMessage("Sorry, there was a problem connecting to the server. Please try again later.");
|
585 |
});
|
586 |
-
|
587 |
-
// // Handle disconnection
|
588 |
-
// socket.on('connect', (reason) => {
|
589 |
-
// // Emit website category via Socket.IO
|
590 |
-
// socket.emit('website', { website: "UAE_Legislation", session_id: 'abc123' });
|
591 |
-
// });
|
592 |
|
593 |
// Handle disconnection
|
594 |
socket.on('disconnect', (reason) => {
|
595 |
console.warn("Disconnected from server:", reason);
|
596 |
response = "";
|
597 |
// appendAnswer("You have been disconnected from the server. Please refresh the page to reconnect.");
|
598 |
-
socket = io.connect('
|
599 |
transports: ['websocket']
|
600 |
});
|
601 |
});
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="ar">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
15 |
<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
|
16 |
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
|
17 |
|
18 |
+
|
19 |
+
<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
|
20 |
+
|
21 |
<script src="https://cdn.tailwindcss.com"></script>
|
22 |
|
23 |
<style>
|
24 |
|
|
|
|
|
|
|
25 |
*:lang(ar-AR){
|
26 |
font-family: "Rubik", sans-serif;
|
27 |
font-optical-sizing: auto;
|
28 |
+
font-style: normal;
|
29 |
}
|
30 |
|
31 |
.main-chat-container{
|
|
|
46 |
font-family: "DM Sans", sans-serif;
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
.chat-container-wrapper * {
|
50 |
font-family: "DM Sans", sans-serif;
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
.chat-container-wrapper a{
|
54 |
color: rgb(11, 172, 235);
|
55 |
text-decoration:underline;
|
|
|
64 |
|
65 |
/* Hide scrollbar for Chrome, Safari and Opera */
|
66 |
.styled-scrolllbar::-webkit-scrollbar {
|
67 |
+
display: none;
|
68 |
}
|
69 |
|
70 |
/* Hide scrollbar for IE, Edge and Firefox */
|
71 |
::-webkit-scrollbar {
|
72 |
+
width: 6px;
|
73 |
+
border-radius: 5px;
|
74 |
}
|
75 |
|
76 |
/* Track */
|
77 |
::-webkit-scrollbar-track {
|
78 |
+
background: #f1f1f1;
|
79 |
}
|
80 |
|
81 |
/* Handle */
|
82 |
::-webkit-scrollbar-thumb {
|
83 |
+
background: #888;
|
84 |
+
border-radius: 10px;
|
85 |
}
|
86 |
|
87 |
/* Handle on hover */
|
88 |
::-webkit-scrollbar-thumb:hover {
|
89 |
+
background: #555;
|
90 |
}
|
91 |
|
92 |
/* Hide scrollbar for Chrome, Safari and Opera */
|
|
|
101 |
}
|
102 |
|
103 |
.question-item:hover{
|
104 |
+
background-color: rgb(245, 245, 245);
|
105 |
}
|
106 |
|
107 |
.sendbtn{
|
|
|
124 |
pointer-events: none;
|
125 |
}
|
126 |
|
|
|
|
|
|
|
|
|
|
|
127 |
.chat-loader {
|
128 |
display: flex;
|
129 |
align-items: center;
|
130 |
gap: 6px;
|
131 |
padding: 8px 10px;
|
132 |
}
|
133 |
+
|
134 |
.chat-loader .dot {
|
135 |
width: 8px;
|
136 |
aspect-ratio: 1;
|
|
|
138 |
background-color: gray;
|
139 |
animation: l5 0.6s ease-in-out infinite;
|
140 |
}
|
141 |
+
|
142 |
.chat-loader .dot:nth-child(1){
|
143 |
animation-delay: 0s;
|
144 |
}
|
145 |
+
|
146 |
.chat-loader .dot:nth-child(2){
|
147 |
animation-delay: 0.2s;
|
148 |
}
|
149 |
+
|
150 |
.chat-loader .dot:nth-child(3){
|
151 |
animation-delay: 0.3s;
|
152 |
}
|
153 |
+
|
154 |
.message-content *{
|
155 |
width: 100%;
|
156 |
+
font-size: 18px;
|
157 |
}
|
158 |
+
|
159 |
.neumorphic-box-shadow{
|
160 |
border-radius: 50px;
|
161 |
background: #e0e0e0;
|
|
|
194 |
.bg-special-secondary{
|
195 |
background-color: rgb(230, 230, 230);
|
196 |
}
|
197 |
+
|
198 |
.message-content *:not(i){
|
199 |
font-family: "DM Sans", sans-serif;
|
200 |
}
|
|
|
203 |
color: black;
|
204 |
font-weight: bold;
|
205 |
}
|
206 |
+
|
207 |
.message-content h3:not(:first-of-type){
|
208 |
margin: 18px 0px 10px 0px;
|
209 |
color: black;
|
210 |
}
|
211 |
+
|
212 |
.message-content h4{
|
213 |
margin: 15px 0px 8px 0px;
|
214 |
}
|
215 |
+
|
216 |
.message-content h5, .message-content h6{
|
217 |
margin: 12px 0px 6px 0px;
|
218 |
}
|
219 |
+
|
220 |
.message-content ol, .message-content ul{
|
221 |
margin: 18px 0px;
|
222 |
+
list-style-type:disc;
|
223 |
+
list-style-position: outside;
|
224 |
+
padding-right: 40px;
|
225 |
}
|
226 |
+
|
227 |
.message-content ol li, .message-content ul li{
|
228 |
margin: 12px 0px ;
|
229 |
}
|
230 |
+
|
231 |
+
.response-block .message-content p{
|
232 |
margin-bottom: 18px;
|
233 |
text-wrap: pretty;
|
234 |
}
|
235 |
+
|
236 |
.message-content a{
|
237 |
text-wrap: pretty;
|
238 |
}
|
239 |
+
|
240 |
.loading-text{
|
241 |
position: relative;
|
242 |
}
|
243 |
+
|
244 |
.loading-text::after{
|
245 |
content: '....';
|
246 |
animation: loading-text-animation 1s infinite;
|
247 |
}
|
248 |
+
|
249 |
@keyframes loading-text-animation {
|
250 |
0%{
|
251 |
content: ''
|
|
|
277 |
direction: ltr;
|
278 |
unicode-bidi: embed;
|
279 |
}
|
280 |
+
|
281 |
+
ol, ul{
|
282 |
+
list-style: disc;
|
283 |
+
padding-right: 40px;
|
284 |
+
list-style-position: outside;
|
285 |
+
}
|
286 |
</style>
|
287 |
|
288 |
|
|
|
309 |
<hr>
|
310 |
|
311 |
|
312 |
+
<div class="relative chat-container w-full mx-auto hide-scrolllbar rounded-xl mb-20 flex flex-col my-8" style="max-width: 900px; flex-grow: 1; padding: 20px 0px; text-wrap: pretty; overflow-y: auto; overflow-x: hidden;">
|
313 |
<div class="start-block load-chat-block w-full flex-grow flex flex-col items-center justify-center bg-white z-10">
|
314 |
<div class="w-full flex-grow flex flex-col items-center justify-center y-4 text-center">
|
315 |
<img src="./static/bg-image.jpg" class="w-1/2" alt="adafsa-logo">
|
|
|
385 |
</div>
|
386 |
</div>
|
387 |
</div>
|
|
|
388 |
</div>
|
389 |
|
390 |
<div class="absolute w-full h-full top-0 left-0 z-0 flex items-center justify-center">
|
|
|
413 |
<script>
|
414 |
|
415 |
// Initialize Socket.IO client
|
416 |
+
var socket = io.connect('http://127.0.0.1:5000/', {
|
417 |
transports: ['websocket']
|
418 |
});
|
419 |
|
|
|
436 |
const isRTL = true;
|
437 |
$(".chat-container").append(
|
438 |
`
|
439 |
+
<div class="chat-block load-chat-block w-full flex flex-row-reverse items-start justify-end bg-secondary p-5 rounded-2xl rtl z-10 bg-gray-100/60">
|
440 |
<div class="flex items-center order-2" >
|
441 |
<span class="bg-white" style="width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50px; padding: 5px; border: 2px solid #c2c2c2;">
|
442 |
<svg fill="#000000" width="36px" height="36px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M21.928 11.607c-.202-.488-.635-.605-.928-.633V8c0-1.103-.897-2-2-2h-6V4.61c.305-.274.5-.668.5-1.11a1.5 1.5 0 0 0-3 0c0 .442.195.836.5 1.11V6H5c-1.103 0-2 .897-2 2v2.997l-.082.006A1 1 0 0 0 1.99 12v2a1 1 0 0 0 1 1H3v5c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5a1 1 0 0 0 1-1v-1.938a1.006 1.006 0 0 0-.072-.455zM5 20V8h14l.001 3.996L19 12v2l.001.005.001 5.995H5z"></path><ellipse cx="8.5" cy="12" rx="1.5" ry="2"></ellipse><ellipse cx="15.5" cy="12" rx="1.5" ry="2"></ellipse><path d="M8 16h8v2H8z"></path></g></svg>
|
|
|
469 |
formatted_question = converter.makeHtml(formatted_question);
|
470 |
|
471 |
$(".chat-container").append(`
|
472 |
+
<div class="chat-block question-block w-full flex flex-row-reverse items-start justify-end p-5 z-10 rounded-2xl bg-white/60">
|
473 |
<div class="flex items-center order-2 bg-white rounded-full">
|
474 |
<span style="width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50px; padding: 3px; border: 2px solid #c2c2c2;">
|
475 |
<svg fill="#000000" width="36px" height="36px" viewBox="0 0 256 256" id="Flat" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M128,76a44,44,0,1,1-44,44A43.99983,43.99983,0,0,1,128,76Zm48-12h16V80a8,8,0,0,0,16,0V64h16a8,8,0,0,0,0-16H208V32a8,8,0,0,0-16,0V48H176a8,8,0,0,0,0,16Zm45.56006,40.95605a8.00039,8.00039,0,0,0-6.64893,9.15381A89.00044,89.00044,0,0,1,216,128a87.63672,87.63672,0,0,1-22.24182,58.41016,79.7044,79.7044,0,0,0-24.431-22.97461,59.83641,59.83641,0,0,1-82.6543,0A79.70345,79.70345,0,0,0,62.2417,186.41016,87.9498,87.9498,0,0,1,128,40a89.02966,89.02966,0,0,1,13.89062,1.08887,7.99994,7.99994,0,1,0,2.50391-15.80274A104.0826,104.0826,0,0,0,24,128a103.74716,103.74716,0,0,0,33.81934,76.68066,7.94507,7.94507,0,0,0,1.32629,1.18946,103.784,103.784,0,0,0,137.71252-.00293,7.94633,7.94633,0,0,0,1.31678-1.18115A103.74751,103.74751,0,0,0,232,128a105.04749,105.04749,0,0,0-1.28613-16.39453A7.99752,7.99752,0,0,0,221.56006,104.95605Z"></path> </g></svg>
|
|
|
508 |
function appendAnswer(answer) {
|
509 |
let lastElement = $(".chat-container .chat-block:last-child");
|
510 |
|
511 |
+
const englishRegex = /[0-9]+(?:\.[0-9]+)?/g;
|
512 |
|
513 |
// Wrap English text and numbers in <span dir="ltr">
|
514 |
formatted_answer = answer.replace(englishRegex, function(match) {
|
515 |
return `<span class="special-span px-1" dir="ltr">${match}</span>`;
|
516 |
});
|
517 |
|
|
|
|
|
518 |
if (lastElement.hasClass("response-block")) {
|
519 |
$(".chat-container .chat-block:last-child").find(".message-content").html(formatted_answer);
|
520 |
} else {
|
521 |
lastElement.remove();
|
522 |
$(".chat-container").append(`
|
523 |
+
<div class="chat-block response-block w-full flex flex-row-reverse items-start justify-end bg-secondary p-5 rounded-2xl rtl z-10 bg-gray-100/60">
|
524 |
<div class="flex items-center order-2" >
|
525 |
<span class="bg-white" style="width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50px; padding: 5px; border: 2px solid #c2c2c2;">
|
526 |
<svg fill="#000000" width="36px" height="36px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M21.928 11.607c-.202-.488-.635-.605-.928-.633V8c0-1.103-.897-2-2-2h-6V4.61c.305-.274.5-.668.5-1.11a1.5 1.5 0 0 0-3 0c0 .442.195.836.5 1.11V6H5c-1.103 0-2 .897-2 2v2.997l-.082.006A1 1 0 0 0 1.99 12v2a1 1 0 0 0 1 1H3v5c0 1.103.897 2 2 2h14c1.103 0 2-.897 2-2v-5a1 1 0 0 0 1-1v-1.938a1.006 1.006 0 0 0-.072-.455zM5 20V8h14l.001 3.996L19 12v2l.001.005.001 5.995H5z"></path><ellipse cx="8.5" cy="12" rx="1.5" ry="2"></ellipse><ellipse cx="15.5" cy="12" rx="1.5" ry="2"></ellipse><path d="M8 16h8v2H8z"></path></g></svg>
|
527 |
</span>
|
528 |
</div>
|
529 |
<div class="px-3 py-1">
|
530 |
+
<div class="message-content pr-2" style="width: 100%; height: 100%; margin: auto; text-wrap: pretty;" style="-webkit-locale: "ar";" >
|
531 |
${formatted_answer}
|
532 |
</div>
|
533 |
</div>
|
|
|
586 |
console.error("Connection error:", error);
|
587 |
appendMessage("Sorry, there was a problem connecting to the server. Please try again later.");
|
588 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
589 |
|
590 |
// Handle disconnection
|
591 |
socket.on('disconnect', (reason) => {
|
592 |
console.warn("Disconnected from server:", reason);
|
593 |
response = "";
|
594 |
// appendAnswer("You have been disconnected from the server. Please refresh the page to reconnect.");
|
595 |
+
socket = io.connect('http://127.0.0.1:5000/', {
|
596 |
transports: ['websocket']
|
597 |
});
|
598 |
});
|