-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
37 lines (33 loc) · 1.27 KB
/
server.py
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
from fastapi import FastAPI, WebSocket
from fastapi.responses import HTMLResponse
from configs import *
from llm import *
import logging
logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
app = FastAPI()
@app.get("/")
async def webpage():
with open("vision.html", "r") as file:
html_content = file.read()
html_content = html_content.replace("[paste_tunnel_url_here]", WSS_TUNNEL_URL)
return HTMLResponse(content=html_content)
@app.websocket("/vision/")
async def visionEndpoint(websocket: WebSocket):
llm_obj = llm()
await websocket.accept()
try:
images = []
count = 0
while True:
if count == MAX_FRAMES:
llm_response = await llm_obj.generate_with_image(VISION_PROMPT, VISION_USER_CONTENT, images)
if "activity_description" in llm_response:
await websocket.send_text("\n".join(llm_response["activity_description"]))
count = 0
images = []
else:
image_bytes_data = await websocket.receive_text()
images.append(image_bytes_data)
count += 1
except Exception as e:
logging.info("Vision Web socket [Stopped] - from server")