Spaces:
Sleeping
Sleeping
Moshe Ofer
commited on
Commit
·
3ef4ce6
1
Parent(s):
c6702f5
Initial commit for Hugging Face Space
Browse files- Dockerfile +2 -0
- templates/index.html +38 -7
Dockerfile
CHANGED
@@ -9,6 +9,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
9 |
|
10 |
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
11 |
ENV HF_HOME=/app/cache
|
|
|
|
|
12 |
|
13 |
COPY . /app
|
14 |
|
|
|
9 |
|
10 |
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
11 |
ENV HF_HOME=/app/cache
|
12 |
+
ENV PYTHONUNBUFFERED=1
|
13 |
+
ENV EVENTLET_NO_GREENDNS=yes
|
14 |
|
15 |
COPY . /app
|
16 |
|
templates/index.html
CHANGED
@@ -396,7 +396,13 @@
|
|
396 |
</div>
|
397 |
|
398 |
<script>
|
399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
let beams = {};
|
401 |
let completedBeams = [];
|
402 |
let isGenerating = false;
|
@@ -412,11 +418,22 @@
|
|
412 |
|
413 |
function setupSocketListeners() {
|
414 |
socket.on('beam_update', function(data) {
|
|
|
415 |
const { beam_idx, text } = data;
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
});
|
421 |
|
422 |
socket.on('beam_finished', function(data) {
|
@@ -475,20 +492,30 @@
|
|
475 |
|
476 |
function resetConnection() {
|
477 |
if (socket) {
|
478 |
-
socket.
|
|
|
479 |
}
|
480 |
-
socket = io(
|
|
|
|
|
|
|
|
|
|
|
481 |
setupSocketListeners();
|
482 |
}
|
483 |
|
484 |
function generate() {
|
485 |
if (isGenerating) return;
|
486 |
|
|
|
|
|
|
|
487 |
document.getElementById('beams').innerHTML = '';
|
488 |
document.getElementById('completed-list').innerHTML = '';
|
489 |
beams = {};
|
490 |
completedBeams = [];
|
491 |
|
|
|
492 |
resetConnection();
|
493 |
|
494 |
const prompt = document.getElementById('prompt').value;
|
@@ -496,6 +523,10 @@
|
|
496 |
const maxTokens = parseInt(document.getElementById('max_tokens').value);
|
497 |
const sleepTime = parseInt(document.getElementById('sleep_time').value);
|
498 |
|
|
|
|
|
|
|
|
|
499 |
socket.emit('generate', {
|
500 |
prompt: prompt,
|
501 |
num_beams: numBeams,
|
|
|
396 |
</div>
|
397 |
|
398 |
<script>
|
399 |
+
// Replace the socket initialization with:
|
400 |
+
let socket = io({
|
401 |
+
transports: ['websocket'],
|
402 |
+
reconnection: true,
|
403 |
+
reconnectionAttempts: 5,
|
404 |
+
reconnectionDelay: 1000
|
405 |
+
});
|
406 |
let beams = {};
|
407 |
let completedBeams = [];
|
408 |
let isGenerating = false;
|
|
|
418 |
|
419 |
function setupSocketListeners() {
|
420 |
socket.on('beam_update', function(data) {
|
421 |
+
console.log('Received beam update:', data); // Add logging
|
422 |
const { beam_idx, text } = data;
|
423 |
+
|
424 |
+
requestAnimationFrame(() => {
|
425 |
+
if (!beams[beam_idx]) {
|
426 |
+
createBeamContainer(beam_idx);
|
427 |
+
}
|
428 |
+
const beamElement = document.getElementById(`beam-${beam_idx}`);
|
429 |
+
if (beamElement) {
|
430 |
+
beamElement.textContent = text;
|
431 |
+
// Force a reflow to ensure the update is visible
|
432 |
+
beamElement.style.display = 'none';
|
433 |
+
beamElement.offsetHeight; // Force reflow
|
434 |
+
beamElement.style.display = 'block';
|
435 |
+
}
|
436 |
+
});
|
437 |
});
|
438 |
|
439 |
socket.on('beam_finished', function(data) {
|
|
|
492 |
|
493 |
function resetConnection() {
|
494 |
if (socket) {
|
495 |
+
socket.removeAllListeners();
|
496 |
+
socket.close();
|
497 |
}
|
498 |
+
socket = io({
|
499 |
+
transports: ['websocket'],
|
500 |
+
reconnection: true,
|
501 |
+
reconnectionAttempts: 5,
|
502 |
+
reconnectionDelay: 1000
|
503 |
+
});
|
504 |
setupSocketListeners();
|
505 |
}
|
506 |
|
507 |
function generate() {
|
508 |
if (isGenerating) return;
|
509 |
|
510 |
+
console.log('Starting generation...'); // Add logging
|
511 |
+
|
512 |
+
// Clear previous state
|
513 |
document.getElementById('beams').innerHTML = '';
|
514 |
document.getElementById('completed-list').innerHTML = '';
|
515 |
beams = {};
|
516 |
completedBeams = [];
|
517 |
|
518 |
+
// Reset connection before each generation
|
519 |
resetConnection();
|
520 |
|
521 |
const prompt = document.getElementById('prompt').value;
|
|
|
523 |
const maxTokens = parseInt(document.getElementById('max_tokens').value);
|
524 |
const sleepTime = parseInt(document.getElementById('sleep_time').value);
|
525 |
|
526 |
+
console.log('Emitting generate event with params:', {
|
527 |
+
prompt, numBeams, maxTokens, sleepTime
|
528 |
+
});
|
529 |
+
|
530 |
socket.emit('generate', {
|
531 |
prompt: prompt,
|
532 |
num_beams: numBeams,
|