Spaces:
Paused
Paused
File size: 1,217 Bytes
1e28d04 2a5e5fa 9a6620f 1e28d04 9a6620f 1e28d04 05dc8f9 1e28d04 9a6620f a3ccca5 05dc8f9 a3ccca5 05dc8f9 a3ccca5 1e28d04 05dc8f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
from fastapi import FastAPI, WebSocket
from fastapi.responses import HTMLResponse
from answerer import Answerer
answerer = Answerer(
repo="BlinkDL/rwkv-5-world",
filename="RWKV-5-World-3B-v2-20231118-ctx16k",
vocab="rwkv_vocab_v20230424",
strategy="cpu bf16",
ctx_limit=16*1024,
)
app = FastAPI()
HTML = """
<!DOCTYPE HTML>
<html>
<body>
<form action="" onsubmit="sendMessage(event)">
<input id="prompt" type="text" autocomplete="off" />
<br>
<input type="submit" value="SEND" />
</form>
<p id="output"></p>
<script>
const prompt = document.getElementById("prompt");
const output = document.getElementById("output");
const ws = new WebSocket("ws://huggingface.co/spaces/DaniilAlpha/answerer-api:8000/answer");
ws.onmessage = function (event) => output.innerText = event.data;
function ask(event) {
ws.send(prompt.value);
event.preventDefault();
}
</script>
</body>
</html>
"""
@app.get("/")
async def index():
return HTMLResponse(HTML)
@app.websocket("/answer")
async def answer(ws: WebSocket):
await ws.accept()
input = await ws.receive_text()
stream = answerer(input, 256)
for el in stream:
await ws.send_text(el) |