Spaces:
Paused
Paused
Commit
·
9e7b790
1
Parent(s):
ebc9ef0
Update main.py
Browse files
main.py
CHANGED
|
@@ -31,14 +31,21 @@ HTML = """
|
|
| 31 |
const output = document.getElementById("output");
|
| 32 |
|
| 33 |
const ws = new WebSocket("wss://daniilalpha-answerer-api.hf.space/answer");
|
| 34 |
-
ws.
|
| 35 |
-
ws.onclose = (e) => console.log(`socket closed with code ${e.code}!`);
|
| 36 |
-
ws.onmessage = (e) => output.innerText = e.data;
|
| 37 |
|
| 38 |
function ask(event) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
ws.send(prompt.value);
|
| 40 |
event.preventDefault();
|
| 41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
</script>
|
| 43 |
</body>
|
| 44 |
|
|
|
|
| 31 |
const output = document.getElementById("output");
|
| 32 |
|
| 33 |
const ws = new WebSocket("wss://daniilalpha-answerer-api.hf.space/answer");
|
| 34 |
+
ws.onmessage = (e) => answer(e.data);
|
|
|
|
|
|
|
| 35 |
|
| 36 |
function ask(event) {
|
| 37 |
+
if(ws.readyState != 1) {
|
| 38 |
+
answer("websocket is not connected!");
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
ws.send(prompt.value);
|
| 43 |
event.preventDefault();
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
function answer(value) {
|
| 47 |
+
output.innerHTML = value;
|
| 48 |
+
}
|
| 49 |
</script>
|
| 50 |
</body>
|
| 51 |
|