Spaces:
Runtime error
Runtime error
Update main.py
Browse files- app/main.py +4 -16
app/main.py
CHANGED
@@ -73,33 +73,21 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int):
|
|
73 |
await manager.broadcast(json.dumps(message))
|
74 |
|
75 |
|
76 |
-
def
|
77 |
t0 = time.time()
|
78 |
-
for i in
|
79 |
print(f"Chunk being yielded (time {int((time.time()-t0)*1000)}ms)", flush=True)
|
80 |
-
yield
|
81 |
time.sleep(0.5)
|
82 |
print(f"Over (time {int((time.time()-t0)*1000)}ms)", flush=True)
|
83 |
|
84 |
|
85 |
-
async def astreamer(generator):
|
86 |
-
try:
|
87 |
-
print("streaming........")
|
88 |
-
for i in generator:
|
89 |
-
print(i)
|
90 |
-
yield (i)
|
91 |
-
await asyncio.sleep(.1)
|
92 |
-
except asyncio.CancelledError as e:
|
93 |
-
yield ('cancelled')
|
94 |
-
|
95 |
-
|
96 |
@app.get("/query")
|
97 |
async def process_input(text: str):
|
98 |
if text and len(text.strip()) > 0:
|
99 |
text = text.strip()
|
100 |
streaming_response = session_assistant.ask(text)
|
101 |
-
return StreamingResponse(
|
102 |
-
# return StreamingResponse(astreamer(streaming_response.response_gen), media_type='text/event-stream')
|
103 |
|
104 |
|
105 |
@app.post("/upload")
|
|
|
73 |
await manager.broadcast(json.dumps(message))
|
74 |
|
75 |
|
76 |
+
def astreamer(generator):
|
77 |
t0 = time.time()
|
78 |
+
for i in generator:
|
79 |
print(f"Chunk being yielded (time {int((time.time()-t0)*1000)}ms)", flush=True)
|
80 |
+
yield i
|
81 |
time.sleep(0.5)
|
82 |
print(f"Over (time {int((time.time()-t0)*1000)}ms)", flush=True)
|
83 |
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
@app.get("/query")
|
86 |
async def process_input(text: str):
|
87 |
if text and len(text.strip()) > 0:
|
88 |
text = text.strip()
|
89 |
streaming_response = session_assistant.ask(text)
|
90 |
+
return StreamingResponse(astreamer(streaming_response.response_gen), media_type='text/event-stream')
|
|
|
91 |
|
92 |
|
93 |
@app.post("/upload")
|