-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
270 lines (231 loc) · 8.84 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FAQ PORTAL</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
margin: 0;
color: #ffffff;
}
.glass {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(15px);
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 10px 50px rgba(31, 38, 135, 0.5);
border-radius: 20px;
padding: 3rem;
width: 100%;
max-width: 800px;
overflow: hidden;
}
.input-focus {
transition: all 0.3s ease;
}
.input-focus:focus {
box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.5);
border-color: #8b5cf6;
}
textarea {
text-align: left;
color: black;
}
textarea::placeholder {
color: rgba(255, 255, 255, 0.5);
}
.section-container {
margin: 1rem 0;
position: relative;
}
.icon-container {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: -1rem;
background: rgba(139, 92, 246, 0.3);
padding: 0.5rem;
border-radius: 50%;
border: 2px solid rgba(255, 255, 255, 0.2);
z-index: 10;
}
.divider {
width: 100%;
height: 1px;
background: rgba(255, 255, 255, 0.2);
margin: 1rem 0;
}
button {
transition: all 0.3s ease;
}
button:hover {
transform: translateY(-3px);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
.mic-button {
background-color: rgba(124, 58, 237, 0.8);
border: none;
color: white;
border-radius: 50%;
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.mic-button.active {
background-color: red;
}
.mic-button:hover {
background-color: rgba(124, 58, 237, 1);
}
</style>
</head>
<body>
<div class="glass rounded-3xl p-8">
<div class="text-center space-y-4 mb-4">
<h1 class="text-4xl font-bold mb-2">SARC FAQ PORTAL</h1>
<p class="text-purple-200 text-lg">Got Queries? Ask Here!</p>
</div>
<div class="mx-auto">
<div class="section-container">
<textarea
id="question"
class="w-full h-20 px-4 py-2 bg-white bg-opacity-20 rounded-2xl text-white placeholder-purple-200 input-focus resize-none text-lg"
placeholder="Type your question here..."
></textarea>
<div class="absolute bottom-2 left-1/2 transform -translate-x-1/2 text-purple-200 text-md">
<span id="charCount">0</span>/500
</div>
<button id="micButton" class="mic-button absolute right-2 bottom-2">
<i class="fas fa-microphone"></i>
</button>
</div>
<div class="divider"></div>
<div class="my-4">
<button
id="submitBtn"
class="w-full bg-purple-600 hover:bg-purple-700 text-white font-semibold py-3 rounded-xl flex items-center justify-center gap-2 text-lg"
>
<span>Get Answer</span>
<i class="fas fa-paper-plane"></i>
<div id="spinner" class="loading-spinner text-lg" style="display: none;">
<i class="fas fa-circle-notch fa-spin"></i>
</div>
</button>
</div>
<div class="divider"></div>
<div class="section-container">
<textarea
id="answer"
class="w-full h-40 px-4 py-4 bg-white bg-opacity-20 rounded-2xl text-white placeholder-purple-200 resize-none text-lg"
readonly
placeholder="Your answer will appear here..."
></textarea>
</div>
</div>
<div class="text-center text-purple-200 text-md mt-4">
<p>Powered by Advanced AI Technology</p>
</div>
</div>
<script>
const questionInput = document.getElementById('question');
const charCount = document.getElementById('charCount');
const submitBtn = document.getElementById('submitBtn');
questionInput.addEventListener('input', function() {
const count = this.value.length;
charCount.textContent = count;
if (count > 500) {
charCount.classList.add('text-red-400');
} else {
charCount.classList.remove('text-red-400');
}
});
questionInput.addEventListener('keypress', function(event) {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
getAnswer();
}
});
submitBtn.addEventListener('click', getAnswer);
const micButton = document.getElementById('micButton');
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.interimResults = true;
recognition.lang = 'en-US';
micButton.addEventListener('click', () => {
micButton.classList.add('active');
recognition.start();
micButton.disabled = true;
});
recognition.addEventListener('result', (event) => {
let transcript = '';
for (const res of event.results) {
transcript += res[0].transcript;
}
questionInput.value = transcript;
if (event.results[0].isFinal) {
micButton.classList.remove('active');
micButton.disabled = false;
getAnswer();
}
});
recognition.addEventListener('end', () => {
micButton.classList.remove('active');
micButton.disabled = false;
});
async function getAnswer() {
const question = questionInput.value;
const answerField = document.getElementById('answer');
const spinner = document.getElementById('spinner');
const button = document.querySelector('button');
if (!question.trim()) {
answerField.value = 'Please enter a question first.';
answerField.style.textAlign = 'center';
answerField.classList.add('text-red-300');
setTimeout(() => {
answerField.value = '';
answerField.classList.remove('text-red-300');
}, 2000);
return;
}
try {
spinner.style.display = 'block';
button.disabled = true;
answerField.value = 'Thinking...';
answerField.style.textAlign = 'center';
const response = await fetch('https://faq-mass-sarc.onrender.com/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ question: question })
});
if (!response.ok) {
throw new Error('API request failed');
}
const data = await response.json();
answerField.value = data.most_similar_answer || 'No answer found.';
answerField.style.textAlign = 'left';
} catch (error) {
answerField.value = 'Sorry, I encountered an error. Please try again.';
answerField.style.textAlign = 'center';
console.error('Error:', error);
} finally {
spinner.style.display = 'none';
button.disabled = false;
}
}
</script>
</body>
</html>