Skip to content

Commit d0a15d1

Browse files
committed
parameterized ports in the html
1 parent 06abc88 commit d0a15d1

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

packages/llm/local_llm/agents/video_query.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __init__(self, model="liuhaotian/llava-v1.5-13b", nanodb=None, vision_scalin
9292
path=nanodb,
9393
model=None, # disable DB's model because VLM's CLIP is used
9494
reserve=kwargs.get('nanodb_reserve'),
95-
k=8, drop_inputs=True,
95+
k=12, drop_inputs=True,
9696
).start().add(self.on_search)
9797
self.llm.add(self.on_image_embedding, channel=ChatQuery.OutputImageEmbedding)
9898
else:
@@ -106,14 +106,35 @@ def __init__(self, model="liuhaotian/llava-v1.5-13b", nanodb=None, vision_scalin
106106

107107
mounts['/data/datasets/uploads'] = '/images/uploads'
108108

109+
video_source = self.video_source.stream.GetOptions()['resource']
110+
video_output = self.video_output.stream.GetOptions()['resource']
111+
112+
webrtc_args = {}
113+
114+
if video_source['protocol'] == 'webrtc':
115+
webrtc_args.update(dict(webrtc_input_stream=video_source['path'].strip('/'),
116+
webrtc_input_port=video_source['port'],
117+
send_webrtc=True))
118+
else:
119+
webrtc_args.update(dict(webrtc_input_stream='input',
120+
webrtc_input_port=8554,
121+
send_webrtc=False))
122+
123+
if video_output['protocol'] == 'webrtc':
124+
webrtc_args.update(dict(webrtc_output_stream=video_output['path'].strip('/'),
125+
webrtc_output_port=video_output['port']))
126+
else:
127+
webrtc_args.update(dict(webrtc_output_stream='output',
128+
webrtc_output_port=8554))
129+
109130
self.server = WebServer(
110131
msg_callback=self.on_websocket,
111132
index='video_query.html',
112-
send_webrtc=False,
113133
title="LIVE LLAVA",
114134
model=os.path.basename(model),
115135
mounts=mounts,
116136
nanodb=nanodb,
137+
**webrtc_args,
117138
**kwargs
118139
)
119140

packages/llm/local_llm/web/templates/video_query.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
};
3636

3737
function sendWebRTC() {
38-
if( sendStream(getWebsocketURL('input'), document.getElementById('send-stream').value) )
38+
if( sendStream(getWebsocketURL("{{ webrtc_input_stream }}", port={{ webrtc_input_port }}), document.getElementById('send-stream').value) )
3939
play(); // autoplay browser stream
4040
}
4141

@@ -50,9 +50,9 @@
5050
for( let n=0; n < search_results.length; n++ ) {
5151
if( 'image' in search_results[n] ) {
5252
//contents = '<div style="position: relative; text-align: center; color: white" width="50%">';
53-
let contents = '<div class="me-1" style="position: relative; color: white; display: inline;">';
54-
contents += `<img src=${search_results[n]['image']} style="aspect-ratio: 1.47; width: 49%;" title="&quot;METADATA&quot; : ${search_results[n]['metadata']}">`;
55-
contents += `<div class="ps-1 pe-1" style="position: absolute; top: 0%; right: 0%; transform: translate(0%, -288%); background-color: rgba(0,0,0,0.5)">${search_results[n]['similarity']}</div></div>`;
53+
let contents = '<div class="me-1" style="position: relative; color: white; display: inline;">'; // 49% width, -288% translate for 2x4 grid
54+
contents += `<img src=${search_results[n]['image']} style="aspect-ratio: 1.47; width: 32%;" title="&quot;METADATA&quot; : ${search_results[n]['metadata']}">`;
55+
contents += `<div class="ps-1 pe-1" style="position: absolute; top: 0%; right: 0%; transform: translate(0%, -168%); background-color: rgba(0,0,0,0.5)">${search_results[n]['similarity']}</div></div>`;
5656
//contents += '</div>';
5757
obj.append(contents);
5858
}
@@ -82,7 +82,7 @@
8282
var sendStream = document.getElementById('send-stream');
8383
var sendButton = document.getElementById('send-button');
8484

85-
playStream.value = getWebsocketURL('output');
85+
playStream.value = getWebsocketURL("{{ webrtc_output_stream }}", port={{ webrtc_output_port }});
8686

8787
{% if send_webrtc %}
8888
// populate the list of browser video devices (requires HTTPS)
@@ -113,7 +113,7 @@
113113
playWebRTC();
114114
{% endif %}
115115

116-
connectWebsocket(onWebsocketMsg, port=49000);
116+
connectWebsocket(onWebsocketMsg, port={{ ws_port }});
117117

118118
event_table = new Tabulator("#event_table", {
119119
columns: [
@@ -373,10 +373,10 @@ <h5 class="d-inline">NanoDB</h5>
373373
{% if send_webrtc %}
374374
<div class="row">
375375
<label for="send-stream" class="col-2" style="width: 6rem;">Webcam:</label>
376-
<div class="col-6">
376+
<div class="col-5">
377377
<select id="send-stream" name="send-stream"></select>
378378
</div>
379-
<div class="col-4">
379+
<div class="col-4 ms-3">
380380
<button id="send-button" onclick="sendWebRTC()">Send</button>
381381
</div>
382382
</div>

0 commit comments

Comments
 (0)