Spaces:
Running
Running
Update main.py
Browse files- app/main.py +18 -1
app/main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import shutil
|
3 |
import json
|
|
|
4 |
from datetime import datetime
|
5 |
from typing import List
|
6 |
from fastapi import FastAPI, UploadFile, WebSocket, WebSocketDisconnect
|
@@ -69,7 +70,23 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int):
|
|
69 |
manager.disconnect(websocket)
|
70 |
message = {"time":current_time,"clientId":client_id,"message":"Offline"}
|
71 |
await manager.broadcast(json.dumps(message))
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
|
75 |
@app.post("/upload")
|
|
|
1 |
import os
|
2 |
import shutil
|
3 |
import json
|
4 |
+
import asyncio
|
5 |
from datetime import datetime
|
6 |
from typing import List
|
7 |
from fastapi import FastAPI, UploadFile, WebSocket, WebSocketDisconnect
|
|
|
70 |
manager.disconnect(websocket)
|
71 |
message = {"time":current_time,"clientId":client_id,"message":"Offline"}
|
72 |
await manager.broadcast(json.dumps(message))
|
73 |
+
|
74 |
+
|
75 |
+
async def astreamer(generator):
|
76 |
+
try:
|
77 |
+
for i in generator:
|
78 |
+
yield (i)
|
79 |
+
await asyncio.sleep(.1)
|
80 |
+
except asyncio.CancelledError as e:
|
81 |
+
print('cancelled')
|
82 |
+
|
83 |
+
|
84 |
+
@app.get("/query")
|
85 |
+
def process_input(text: str):
|
86 |
+
if text and len(text.strip()) > 0:
|
87 |
+
text = text.strip()
|
88 |
+
streaming_response = session_assistant.ask(text)
|
89 |
+
return StreamingResponse(astreamer(streaming_response.response_gen), media_type='text/event-stream')
|
90 |
|
91 |
|
92 |
@app.post("/upload")
|