Spaces:
Paused
Paused
Commit
·
185b88a
1
Parent(s):
db8f766
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
from threading import Thread
|
| 2 |
-
|
| 3 |
from fastapi import FastAPI, WebSocket
|
| 4 |
from fastapi.responses import HTMLResponse
|
| 5 |
|
|
@@ -60,24 +58,10 @@ async def index():
|
|
| 60 |
@app.websocket("/answer")
|
| 61 |
async def answer(ws: WebSocket):
|
| 62 |
await ws.accept()
|
| 63 |
-
|
| 64 |
-
print("ws connected!")
|
| 65 |
-
|
| 66 |
-
def callback(output: str):
|
| 67 |
-
print(f"sent: '{output}'")
|
| 68 |
-
# await ws.send_text(output)
|
| 69 |
|
| 70 |
input = await ws.receive_text()
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
kwargs={"callback": callback}
|
| 75 |
-
)
|
| 76 |
-
answerer_thread.start()
|
| 77 |
-
answerer_thread.join()
|
| 78 |
-
|
| 79 |
-
print("output ready!")
|
| 80 |
-
|
| 81 |
-
await ws.close()
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, WebSocket
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
|
|
|
|
| 58 |
@app.websocket("/answer")
|
| 59 |
async def answer(ws: WebSocket):
|
| 60 |
await ws.accept()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
input = await ws.receive_text()
|
| 63 |
+
output = answerer(input, 32)
|
| 64 |
+
for el in output:
|
| 65 |
+
await ws.send_text(el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
await ws.close()
|