Upload folder using huggingface_hub
Browse files- web/routes/websocket.py +7 -2
- web/static/js/chat.js +17 -0
- web/templates/index.html +6 -0
web/routes/websocket.py
CHANGED
|
@@ -98,8 +98,13 @@ async def websocket_chat(websocket: WebSocket):
|
|
| 98 |
# Get session for this connection (auto-recreate if lost)
|
| 99 |
session = get_session(connection_id)
|
| 100 |
if not session:
|
| 101 |
-
logger.warning(f"Session lost for {connection_id[:8]},
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Callback for streaming
|
| 105 |
async def stream_callback(event_type: str, content: str, **kwargs):
|
|
|
|
| 98 |
# Get session for this connection (auto-recreate if lost)
|
| 99 |
session = get_session(connection_id)
|
| 100 |
if not session:
|
| 101 |
+
logger.warning(f"Session lost for {connection_id[:8]}, requesting keys...")
|
| 102 |
+
# Ask client to resend keys (e.g., after container restart)
|
| 103 |
+
await manager.send_json(websocket, {
|
| 104 |
+
"type": "request_keys",
|
| 105 |
+
"reason": "Session expired, please reconnect."
|
| 106 |
+
})
|
| 107 |
+
continue
|
| 108 |
|
| 109 |
# Callback for streaming
|
| 110 |
async def stream_callback(event_type: str, content: str, **kwargs):
|
web/static/js/chat.js
CHANGED
|
@@ -385,6 +385,7 @@ class EurusChat {
|
|
| 385 |
if (!message || !this.isConnected) return;
|
| 386 |
|
| 387 |
this.addUserMessage(message);
|
|
|
|
| 388 |
this.ws.send(JSON.stringify({ message }));
|
| 389 |
|
| 390 |
this.messageInput.value = '';
|
|
@@ -406,6 +407,22 @@ class EurusChat {
|
|
| 406 |
}
|
| 407 |
break;
|
| 408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
case 'thinking':
|
| 410 |
this.showThinkingIndicator();
|
| 411 |
break;
|
|
|
|
| 385 |
if (!message || !this.isConnected) return;
|
| 386 |
|
| 387 |
this.addUserMessage(message);
|
| 388 |
+
this._lastSentMessage = message;
|
| 389 |
this.ws.send(JSON.stringify({ message }));
|
| 390 |
|
| 391 |
this.messageInput.value = '';
|
|
|
|
| 407 |
}
|
| 408 |
break;
|
| 409 |
|
| 410 |
+
case 'request_keys':
|
| 411 |
+
// Server lost our session (e.g., container restart) — resend keys
|
| 412 |
+
console.warn('Server requested keys:', data.reason);
|
| 413 |
+
this.removeThinkingIndicator();
|
| 414 |
+
this.autoSendSessionKeys();
|
| 415 |
+
// Retry the last message after a short delay for session init
|
| 416 |
+
if (this._lastSentMessage) {
|
| 417 |
+
setTimeout(() => {
|
| 418 |
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
| 419 |
+
this.ws.send(JSON.stringify({ message: this._lastSentMessage }));
|
| 420 |
+
this.showThinkingIndicator();
|
| 421 |
+
}
|
| 422 |
+
}, 3000);
|
| 423 |
+
}
|
| 424 |
+
break;
|
| 425 |
+
|
| 426 |
case 'thinking':
|
| 427 |
this.showThinkingIndicator();
|
| 428 |
break;
|
web/templates/index.html
CHANGED
|
@@ -32,6 +32,12 @@
|
|
| 32 |
<li>"Show me SST for California coast, Jan 2024"</li>
|
| 33 |
<li>"Plot temperature in the Gulf of Mexico"</li>
|
| 34 |
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
</div>
|
| 36 |
</div>
|
| 37 |
|
|
|
|
| 32 |
<li>"Show me SST for California coast, Jan 2024"</li>
|
| 33 |
<li>"Plot temperature in the Gulf of Mexico"</li>
|
| 34 |
</ul>
|
| 35 |
+
<p style="margin-top: 10px; font-size: 0.85em; opacity: 0.7;">
|
| 36 |
+
⚠️ <strong>Experimental</strong> — This is a research prototype. Please avoid requesting very large
|
| 37 |
+
datasets
|
| 38 |
+
(e.g., global multi-year downloads), especially via this HF Space. For heavy workloads, use the
|
| 39 |
+
📦 Arraylake Code buttons to access data directly.
|
| 40 |
+
</p>
|
| 41 |
</div>
|
| 42 |
</div>
|
| 43 |
|