ikraamkb commited on
Commit
54b0885
·
verified ·
1 Parent(s): 8b84edc

Update static/application.js

Browse files
Files changed (1) hide show
  1. static/application.js +47 -4
static/application.js CHANGED
@@ -116,6 +116,53 @@ async function handleSubmit() {
116
  }
117
  */
118
  // frontend.js
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  async function handleSubmit() {
120
  const question = inputField.value.trim();
121
  if (!question && !selectedFile) {
@@ -127,7 +174,6 @@ async function handleSubmit() {
127
  formData.append("question", question);
128
  formData.append("file", selectedFile);
129
 
130
- // Show user question
131
  const userBlock = document.createElement("div");
132
  userBlock.className = "user-block";
133
  userBlock.innerHTML = `
@@ -136,7 +182,6 @@ async function handleSubmit() {
136
  `;
137
  convo.appendChild(userBlock);
138
 
139
- // Loading message
140
  const loadingBlock = document.createElement("div");
141
  loadingBlock.className = "loading-block";
142
  loadingBlock.innerText = "Processing your request...";
@@ -151,7 +196,6 @@ async function handleSubmit() {
151
  const result = await response.json();
152
  loadingBlock.remove();
153
 
154
- // Answer block with optional audio
155
  const answerBlock = document.createElement("div");
156
  answerBlock.className = "answer-block";
157
  answerBlock.innerHTML = `
@@ -165,7 +209,6 @@ async function handleSubmit() {
165
  `;
166
  convo.appendChild(answerBlock);
167
 
168
- // Handle audio toggle
169
  const audioIcon = answerBlock.querySelector(".audio-toggle");
170
  const audioElement = answerBlock.querySelector("audio");
171
 
 
116
  }
117
  */
118
  // frontend.js
119
+ const inputField = document.querySelector(".qt input");
120
+ const icons = document.querySelectorAll(".icons i");
121
+ const convo = document.querySelector(".convo");
122
+ const send = document.querySelector(".sendingQA");
123
+
124
+ const imageInput = document.createElement("input");
125
+ imageInput.type = "file";
126
+ imageInput.accept = "image/*";
127
+ imageInput.style.display = "none";
128
+
129
+ const docInput = document.createElement("input");
130
+ docInput.type = "file";
131
+ docInput.accept = ".pdf,.docx,.pptx,.xlsx";
132
+ docInput.style.display = "none";
133
+
134
+ document.body.appendChild(imageInput);
135
+ document.body.appendChild(docInput);
136
+
137
+ let selectedFile = null;
138
+ let selectedType = null;
139
+
140
+ icons[0].addEventListener("click", () => imageInput.click());
141
+ icons[1].addEventListener("click", () => docInput.click());
142
+ send.addEventListener("click", handleSubmit);
143
+
144
+ imageInput.addEventListener("change", () => {
145
+ selectedFile = imageInput.files[0];
146
+ selectedType = "Image";
147
+ showSelectedFile(selectedFile.name, "🖼️");
148
+ });
149
+
150
+ docInput.addEventListener("change", () => {
151
+ selectedFile = docInput.files[0];
152
+ selectedType = "Document";
153
+ showSelectedFile(selectedFile.name, "📄");
154
+ });
155
+
156
+ function showSelectedFile(fileName, icon) {
157
+ const fileNotice = document.createElement("div");
158
+ fileNotice.style.padding = "0.8rem";
159
+ fileNotice.style.backgroundColor = "#f3f3f3";
160
+ fileNotice.style.borderRadius = "10px";
161
+ fileNotice.style.margin = "1rem";
162
+ fileNotice.innerHTML = `${icon} <strong>Selected file:</strong> ${fileName}`;
163
+ convo.appendChild(fileNotice);
164
+ }
165
+
166
  async function handleSubmit() {
167
  const question = inputField.value.trim();
168
  if (!question && !selectedFile) {
 
174
  formData.append("question", question);
175
  formData.append("file", selectedFile);
176
 
 
177
  const userBlock = document.createElement("div");
178
  userBlock.className = "user-block";
179
  userBlock.innerHTML = `
 
182
  `;
183
  convo.appendChild(userBlock);
184
 
 
185
  const loadingBlock = document.createElement("div");
186
  loadingBlock.className = "loading-block";
187
  loadingBlock.innerText = "Processing your request...";
 
196
  const result = await response.json();
197
  loadingBlock.remove();
198
 
 
199
  const answerBlock = document.createElement("div");
200
  answerBlock.className = "answer-block";
201
  answerBlock.innerHTML = `
 
209
  `;
210
  convo.appendChild(answerBlock);
211
 
 
212
  const audioIcon = answerBlock.querySelector(".audio-toggle");
213
  const audioElement = answerBlock.querySelector("audio");
214