ikraamkb commited on
Commit
326ff42
·
verified ·
1 Parent(s): 8e4e74f

Update static/appS.js

Browse files
Files changed (1) hide show
  1. static/appS.js +74 -75
static/appS.js CHANGED
@@ -76,87 +76,86 @@ document.addEventListener('DOMContentLoaded', () => {
76
  );
77
  }
78
 
79
- function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
80
- const bubble = document.createElement('div');
81
- bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
82
- bubble.style.maxWidth = "50%"; // ✅ Max width 50% of screen
83
- bubble.style.wordWrap = "break-word";
84
-
85
- const label = document.createElement('div');
86
- label.className = "label";
87
- label.textContent = sender;
88
-
89
- const message = document.createElement('div');
90
- message.className = "text";
91
- message.style.whiteSpace = "pre-wrap";
92
- message.style.display = "flex";
93
- message.style.flexDirection = "column";
94
-
95
- const textSpan = document.createElement("span");
96
- textSpan.innerText = text;
97
- message.appendChild(textSpan);
98
-
99
- if (sender !== "You") {
100
- const iconContainer = document.createElement('div');
101
- iconContainer.style.marginTop = "10px";
102
- iconContainer.style.display = "flex";
103
- iconContainer.style.justifyContent = "flex-end";
104
- iconContainer.style.gap = "10px";
105
-
106
- if (audioSrc) {
107
- const audioIcon = document.createElement("i");
108
- audioIcon.className = "fa-solid fa-volume-high audio-toggle";
109
- audioIcon.title = "Click to mute";
110
- audioIcon.style.cursor = "pointer";
111
- audioIcon.style.fontSize = "18px";
112
-
113
- const audio = new Audio(audioSrc);
114
- audio.play();
115
-
116
- audioIcon.addEventListener("click", () => {
117
- if (audio.muted) {
118
- audio.currentTime = 0;
119
- audio.muted = false;
120
- audioIcon.classList.remove("fa-volume-xmark");
121
- audioIcon.classList.add("fa-volume-high");
122
- audioIcon.title = "Click to mute";
123
- audio.play();
124
- } else {
125
- audio.muted = true;
126
- audioIcon.classList.remove("fa-volume-high");
127
- audioIcon.classList.add("fa-volume-xmark");
128
- audioIcon.title = "Click to unmute";
129
- }
130
- });
131
-
132
- iconContainer.appendChild(audioIcon);
133
- }
134
 
135
- if (fileName) {
136
- const downloadIcon = document.createElement("a");
137
- downloadIcon.href = fileName;
138
- downloadIcon.target = "_blank";
139
- downloadIcon.title = "Download PDF";
140
 
141
- const icon = document.createElement("i");
142
- icon.className = "fa-solid fa-file-arrow-down";
143
- icon.style.fontSize = "18px";
144
- icon.style.cursor = "pointer";
 
 
145
 
146
- downloadIcon.appendChild(icon);
147
- iconContainer.appendChild(downloadIcon);
148
- }
 
149
 
150
- message.appendChild(iconContainer);
 
151
  }
152
 
153
- bubble.appendChild(label);
154
- bubble.appendChild(message);
155
- convo.appendChild(bubble);
156
- convo.scrollTop = convo.scrollHeight;
157
- return bubble;
158
  }
159
 
 
 
 
 
 
 
 
 
160
  async function handleSubmit() {
161
  if (!selectedFile) {
162
  alert("Please upload a file first");
@@ -166,7 +165,7 @@ document.addEventListener('DOMContentLoaded', () => {
166
  const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
167
  const endpoint = isSummarizeMode ? '/summarize/' : '/imagecaption/';
168
  const thinkingText = isSummarizeMode ? 'Processing document...' : "Generating caption... <div class='loader'></div>";
169
- const senderName = isSummarizeMode ? 'Assistant' : 'Aidan';
170
 
171
  const thinkingBubble = createMessageBubble(thinkingText, senderName);
172
 
@@ -197,7 +196,7 @@ document.addEventListener('DOMContentLoaded', () => {
197
  if (isSummarizeMode) {
198
  createMessageBubble(
199
  result.summary || "No summary generated.",
200
- "Assistant",
201
  result.audioUrl,
202
  result.pdfUrl
203
  );
 
76
  );
77
  }
78
 
79
+ function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
80
+ const bubble = document.createElement('div');
81
+ bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
82
+ bubble.style.maxWidth = "50%";
83
+ bubble.style.wordWrap = "break-word";
84
+
85
+ const label = document.createElement('div');
86
+ label.className = "label";
87
+ label.textContent = sender;
88
+
89
+ const message = document.createElement('div');
90
+ message.className = "text";
91
+ message.style.whiteSpace = "pre-wrap";
92
+ message.style.display = "flex";
93
+ message.style.flexDirection = "column";
94
+
95
+ const textSpan = document.createElement("span");
96
+ textSpan.innerHTML = text;
97
+ message.appendChild(textSpan);
98
+
99
+ if (sender !== "You" && (audioSrc || fileName)) {
100
+ const iconContainer = document.createElement('div');
101
+ iconContainer.style.marginTop = "10px";
102
+ iconContainer.style.display = "flex";
103
+ iconContainer.style.justifyContent = "flex-end";
104
+ iconContainer.style.gap = "15px";
105
+
106
+ // 🎵 Audio Icon
107
+ if (audioSrc) {
108
+ const audio = new Audio(audioSrc);
109
+ const audioIcon = document.createElement("i");
110
+ audioIcon.className = "fa-solid fa-volume-high audio-toggle";
111
+ audioIcon.title = "Play Audio";
112
+ audioIcon.style.cursor = "pointer";
113
+ audioIcon.style.fontSize = "18px";
114
+
115
+ audioIcon.addEventListener("click", () => {
116
+ if (audio.paused) {
117
+ audio.play();
118
+ audioIcon.classList.remove("fa-volume-xmark");
119
+ audioIcon.classList.add("fa-volume-high");
120
+ audioIcon.title = "Mute Audio";
121
+ } else {
122
+ audio.pause();
123
+ audioIcon.classList.remove("fa-volume-high");
124
+ audioIcon.classList.add("fa-volume-xmark");
125
+ audioIcon.title = "Unmute Audio";
126
+ }
127
+ });
 
 
 
 
 
 
128
 
129
+ iconContainer.appendChild(audioIcon);
130
+ }
 
 
 
131
 
132
+ // 📥 Download Icon
133
+ if (fileName) {
134
+ const downloadLink = document.createElement('a');
135
+ downloadLink.href = fileName;
136
+ downloadLink.target = "_blank";
137
+ downloadLink.title = "Download PDF";
138
 
139
+ const downloadIcon = document.createElement("i");
140
+ downloadIcon.className = "fa-solid fa-file-arrow-down";
141
+ downloadIcon.style.fontSize = "18px";
142
+ downloadIcon.style.cursor = "pointer";
143
 
144
+ downloadLink.appendChild(downloadIcon);
145
+ iconContainer.appendChild(downloadLink);
146
  }
147
 
148
+ message.appendChild(iconContainer);
 
 
 
 
149
  }
150
 
151
+ bubble.appendChild(label);
152
+ bubble.appendChild(message);
153
+ convo.appendChild(bubble);
154
+ convo.scrollTop = convo.scrollHeight;
155
+ return bubble;
156
+ }
157
+
158
+
159
  async function handleSubmit() {
160
  if (!selectedFile) {
161
  alert("Please upload a file first");
 
165
  const isSummarizeMode = document.querySelector('input[name="mode"]:checked').value === 'Summarize';
166
  const endpoint = isSummarizeMode ? '/summarize/' : '/imagecaption/';
167
  const thinkingText = isSummarizeMode ? 'Processing document...' : "Generating caption... <div class='loader'></div>";
168
+ const senderName = 'Aidan';
169
 
170
  const thinkingBubble = createMessageBubble(thinkingText, senderName);
171
 
 
196
  if (isSummarizeMode) {
197
  createMessageBubble(
198
  result.summary || "No summary generated.",
199
+ "Aidan",
200
  result.audioUrl,
201
  result.pdfUrl
202
  );