Spaces:
Paused
Paused
Commit
·
eb6c6fa
1
Parent(s):
1e30c19
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from typing import
|
2 |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
3 |
from fastapi.responses import HTMLResponse, JSONResponse
|
4 |
|
@@ -35,7 +35,7 @@ HTML = """
|
|
35 |
const prompt = document.getElementById("prompt");
|
36 |
const output = document.getElementById("output");
|
37 |
|
38 |
-
const ws = new WebSocket("
|
39 |
ws.onmessage = (e) => answer(e.data);
|
40 |
|
41 |
function ask(event) {
|
@@ -62,14 +62,14 @@ def index():
|
|
62 |
return HTMLResponse(HTML)
|
63 |
|
64 |
@app.get("/map")
|
65 |
-
def map(query: str, items:
|
66 |
indices = mapper(query, items)
|
67 |
return JSONResponse(indices)
|
68 |
|
69 |
@app.websocket("/answer")
|
70 |
async def answer(ws: WebSocket):
|
71 |
-
print("
|
72 |
-
|
73 |
await ws.accept()
|
74 |
|
75 |
print("ws accepted!")
|
|
|
1 |
+
from typing import Union
|
2 |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
3 |
from fastapi.responses import HTMLResponse, JSONResponse
|
4 |
|
|
|
35 |
const prompt = document.getElementById("prompt");
|
36 |
const output = document.getElementById("output");
|
37 |
|
38 |
+
const ws = new WebSocket("ws://127.0.0.1:2403/answer");
|
39 |
ws.onmessage = (e) => answer(e.data);
|
40 |
|
41 |
function ask(event) {
|
|
|
62 |
return HTMLResponse(HTML)
|
63 |
|
64 |
@app.get("/map")
|
65 |
+
def map(query: Union[str, None], items: Union[list[str], None]):
|
66 |
indices = mapper(query, items)
|
67 |
return JSONResponse(indices)
|
68 |
|
69 |
@app.websocket("/answer")
|
70 |
async def answer(ws: WebSocket):
|
71 |
+
print("ws started!")
|
72 |
+
|
73 |
await ws.accept()
|
74 |
|
75 |
print("ws accepted!")
|