add chat interface
This commit is contained in:
parent
cacf4e6638
commit
56338be013
|
@ -49,9 +49,7 @@ export HF_ENDPOINT=https://hf-mirror.com
|
||||||
apt install nginx
|
apt install nginx
|
||||||
nginx
|
nginx
|
||||||
```
|
```
|
||||||
修改echo.html中websocket和视频播放地址,将serverip替换成实际服务器ip
|
将echo.html和mpegts-1.7.3.min.js拷到/var/www/html下
|
||||||
然后将echo.html和mpegts-1.7.3.min.js拷到/var/www/html下
|
|
||||||
|
|
||||||
|
|
||||||
用浏览器打开http://serverip/echo.html, 在文本框输入任意文字,提交。数字人播报该段文字
|
用浏览器打开http://serverip/echo.html, 在文本框输入任意文字,提交。数字人播报该段文字
|
||||||
|
|
||||||
|
|
22
app.py
22
app.py
|
@ -66,7 +66,27 @@ def echo_socket(ws):
|
||||||
if len(message)==0:
|
if len(message)==0:
|
||||||
return '输入信息为空'
|
return '输入信息为空'
|
||||||
else:
|
else:
|
||||||
txt_to_audio(message)
|
txt_to_audio(message)
|
||||||
|
|
||||||
|
@sockets.route('/humanchat')
|
||||||
|
def chat_socket(ws):
|
||||||
|
# 获取WebSocket对象
|
||||||
|
#ws = request.environ.get('wsgi.websocket')
|
||||||
|
# 如果没有获取到,返回错误信息
|
||||||
|
if not ws:
|
||||||
|
print('未建立连接!')
|
||||||
|
return 'Please use WebSocket'
|
||||||
|
# 否则,循环接收和发送消息
|
||||||
|
else:
|
||||||
|
print('建立连接!')
|
||||||
|
while True:
|
||||||
|
message = ws.receive()
|
||||||
|
|
||||||
|
if len(message)==0:
|
||||||
|
return '输入信息为空'
|
||||||
|
else:
|
||||||
|
res=llm(message)
|
||||||
|
txt_to_audio(res)
|
||||||
|
|
||||||
def render():
|
def render():
|
||||||
nerfreal.render()
|
nerfreal.render()
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
<!-- index.html -->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript" src="mpegts-1.7.3.min.js"></script>
|
||||||
|
<script type="text/javascript" src="http://cdn.sockjs.org/sockjs-0.3.4.js"></script>
|
||||||
|
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>WebSocket Test</h1>
|
||||||
|
<form class="form-inline" id="echo-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<p>input text</p>
|
||||||
|
|
||||||
|
<textarea cols="2" rows="3" style="width:600px;height:50px;" class="form-control" id="message">test</textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-default">Send</button>
|
||||||
|
</form>
|
||||||
|
<div id="log">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<video id="video_player" width="40%" controls autoplay muted></video>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
var host = window.location.hostname
|
||||||
|
var ws = new WebSocket("ws://"+host+":8000/humanchat");
|
||||||
|
//document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]);
|
||||||
|
ws.onopen = function() {
|
||||||
|
console.log('Connected');
|
||||||
|
};
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
console.log('Received: ' + e.data);
|
||||||
|
data = e
|
||||||
|
var vid = JSON.parse(data.data);
|
||||||
|
console.log(typeof(vid),vid)
|
||||||
|
//document.getElementsByTagName("video")[0].setAttribute("src", vid["video"]);
|
||||||
|
|
||||||
|
};
|
||||||
|
ws.onclose = function(e) {
|
||||||
|
console.log('Closed');
|
||||||
|
};
|
||||||
|
|
||||||
|
flvPlayer = mpegts.createPlayer({type: 'flv', url: "http://"+host+":8080/live/livestream.flv", isLive: true, enableStashBuffer: false});
|
||||||
|
flvPlayer.attachMediaElement(document.getElementById('video_player'));
|
||||||
|
flvPlayer.load();
|
||||||
|
flvPlayer.play();
|
||||||
|
|
||||||
|
$('#echo-form').on('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var message = $('#message').val();
|
||||||
|
console.log('Sending: ' + message);
|
||||||
|
ws.send(message);
|
||||||
|
$('#message').val('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</html>
|
|
@ -28,7 +28,8 @@
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var ws = new WebSocket('ws://serverip:8000/humanecho');
|
var host = window.location.hostname
|
||||||
|
var ws = new WebSocket("ws://"+host+":8000/humanecho");
|
||||||
//document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]);
|
//document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]);
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
console.log('Connected');
|
console.log('Connected');
|
||||||
|
@ -45,7 +46,7 @@
|
||||||
console.log('Closed');
|
console.log('Closed');
|
||||||
};
|
};
|
||||||
|
|
||||||
flvPlayer = mpegts.createPlayer({type: 'flv', url: "http://serverip:8080/live/livestream.flv", isLive: true, enableStashBuffer: false});
|
flvPlayer = mpegts.createPlayer({type: 'flv', url: "http://"+host+":8080/live/livestream.flv", isLive: true, enableStashBuffer: false});
|
||||||
flvPlayer.attachMediaElement(document.getElementById('video_player'));
|
flvPlayer.attachMediaElement(document.getElementById('video_player'));
|
||||||
flvPlayer.load();
|
flvPlayer.load();
|
||||||
flvPlayer.play();
|
flvPlayer.play();
|
||||||
|
|
Loading…
Reference in New Issue