Spaces:
Sleeping
Sleeping
Commit ·
385854b
1
Parent(s): 868b3c0
updated app
Browse files- app.py +1 -1
- static/app.js +24 -28
app.py
CHANGED
|
@@ -62,7 +62,7 @@ load_model()
|
|
| 62 |
def generate_tokens(image, user_prompt):
|
| 63 |
# Same prompt preparation (unchanged)
|
| 64 |
messages = [
|
| 65 |
-
{"role": "system", "content": "You are a helpful assistant. If you see a person in the image, this is me interacting, so if the question involve me as a personal
|
| 66 |
{"role": "user", "content": f"<image>\n{user_prompt}"}
|
| 67 |
]
|
| 68 |
rendered = tokenizer.apply_chat_template(
|
|
|
|
| 62 |
def generate_tokens(image, user_prompt):
|
| 63 |
# Same prompt preparation (unchanged)
|
| 64 |
messages = [
|
| 65 |
+
{"role": "system", "content": "You are a helpful assistant. If you see a person in the image, this is me interacting, so if the question involve me as a personal, answer it based on my actions. Always answer very briefly and in one sentence while being concise, using only essential information."},
|
| 66 |
{"role": "user", "content": f"<image>\n{user_prompt}"}
|
| 67 |
]
|
| 68 |
rendered = tokenizer.apply_chat_template(
|
static/app.js
CHANGED
|
@@ -105,35 +105,32 @@ function setupVoicer() {
|
|
| 105 |
});
|
| 106 |
}
|
| 107 |
|
| 108 |
-
// Draw video frame to canvas (always
|
| 109 |
function drawVideo() {
|
| 110 |
const width = canvasElement.width;
|
| 111 |
const height = canvasElement.height;
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
offsetX = 0;
|
| 130 |
-
offsetY = (height - drawHeight) / 2;
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
canvasCtx.drawImage(video, offsetX, offsetY, drawWidth, drawHeight);
|
| 134 |
}
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
-
// Always schedule next frame
|
| 137 |
animationFrameId = requestAnimationFrame(drawVideo);
|
| 138 |
}
|
| 139 |
|
|
@@ -219,13 +216,13 @@ function resizeCanvas() {
|
|
| 219 |
}
|
| 220 |
window.addEventListener('resize', resizeCanvas);
|
| 221 |
|
| 222 |
-
// Streamed generation (with resize, FormData, retry, timeout
|
| 223 |
async function generateCaption(retryCount = 0) {
|
| 224 |
const now = Date.now();
|
| 225 |
if (isGenerating || (now - lastGenerationTime < DEBOUNCE_MS)) return;
|
| 226 |
isGenerating = true;
|
| 227 |
lastGenerationTime = now;
|
| 228 |
-
const resizedDataUrl = resizeImageForUpload(canvasElement); //
|
| 229 |
const promptToUse = getPromptToUse();
|
| 230 |
captionDiv.textContent = 'Generating...'; // Better UX
|
| 231 |
sendBtn.disabled = true;
|
|
@@ -239,7 +236,7 @@ async function generateCaption(retryCount = 0) {
|
|
| 239 |
micBtn.classList.add('processing');
|
| 240 |
}
|
| 241 |
|
| 242 |
-
//
|
| 243 |
|
| 244 |
try {
|
| 245 |
const formData = new FormData();
|
|
@@ -282,7 +279,6 @@ async function generateCaption(retryCount = 0) {
|
|
| 282 |
} finally {
|
| 283 |
isGenerating = false;
|
| 284 |
sendBtn.disabled = false;
|
| 285 |
-
// No need to restore drawVideo; loop is always alive
|
| 286 |
if (wasVoiceActive) {
|
| 287 |
promptInput.value = '';
|
| 288 |
isPausedForGeneration = false;
|
|
|
|
| 105 |
});
|
| 106 |
}
|
| 107 |
|
| 108 |
+
// Draw video frame to canvas (always draw, no pause during generation)
|
| 109 |
function drawVideo() {
|
| 110 |
const width = canvasElement.width;
|
| 111 |
const height = canvasElement.height;
|
| 112 |
+
canvasCtx.clearRect(0, 0, width, height);
|
| 113 |
+
|
| 114 |
+
if (video.readyState === video.HAVE_ENOUGH_DATA && video.videoWidth > 0 && video.videoHeight > 0) {
|
| 115 |
+
const videoAspect = video.videoWidth / video.videoHeight;
|
| 116 |
+
const canvasAspect = width / height;
|
| 117 |
+
let drawWidth, drawHeight, offsetX, offsetY;
|
| 118 |
+
|
| 119 |
+
if (videoAspect > canvasAspect) {
|
| 120 |
+
drawHeight = height;
|
| 121 |
+
drawWidth = height * videoAspect;
|
| 122 |
+
offsetX = (width - drawWidth) / 2;
|
| 123 |
+
offsetY = 0;
|
| 124 |
+
} else {
|
| 125 |
+
drawWidth = width;
|
| 126 |
+
drawHeight = width / videoAspect;
|
| 127 |
+
offsetX = 0;
|
| 128 |
+
offsetY = (height - drawHeight) / 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
}
|
| 130 |
+
|
| 131 |
+
canvasCtx.drawImage(video, offsetX, offsetY, drawWidth, drawHeight);
|
| 132 |
}
|
| 133 |
+
// Always schedule next frame
|
| 134 |
animationFrameId = requestAnimationFrame(drawVideo);
|
| 135 |
}
|
| 136 |
|
|
|
|
| 216 |
}
|
| 217 |
window.addEventListener('resize', resizeCanvas);
|
| 218 |
|
| 219 |
+
// Streamed generation (with resize, FormData, retry, timeout)
|
| 220 |
async function generateCaption(retryCount = 0) {
|
| 221 |
const now = Date.now();
|
| 222 |
if (isGenerating || (now - lastGenerationTime < DEBOUNCE_MS)) return;
|
| 223 |
isGenerating = true;
|
| 224 |
lastGenerationTime = now;
|
| 225 |
+
const resizedDataUrl = resizeImageForUpload(canvasElement); // Snapshot at start
|
| 226 |
const promptToUse = getPromptToUse();
|
| 227 |
captionDiv.textContent = 'Generating...'; // Better UX
|
| 228 |
sendBtn.disabled = true;
|
|
|
|
| 236 |
micBtn.classList.add('processing');
|
| 237 |
}
|
| 238 |
|
| 239 |
+
// Live feed continues independently via drawVideo loop
|
| 240 |
|
| 241 |
try {
|
| 242 |
const formData = new FormData();
|
|
|
|
| 279 |
} finally {
|
| 280 |
isGenerating = false;
|
| 281 |
sendBtn.disabled = false;
|
|
|
|
| 282 |
if (wasVoiceActive) {
|
| 283 |
promptInput.value = '';
|
| 284 |
isPausedForGeneration = false;
|