From 56338be0134da80d7f1a568b7195230fa85c9754 Mon Sep 17 00:00:00 2001 From: lihengzhong Date: Sat, 27 Jan 2024 11:13:16 +0800 Subject: [PATCH] add chat interface --- README.md | 4 +--- app.py | 22 ++++++++++++++++++- chat.html | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ echo.html | 5 +++-- 4 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 chat.html diff --git a/README.md b/README.md index 6f7e994..93a885e 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,7 @@ export HF_ENDPOINT=https://hf-mirror.com apt install 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, 在文本框输入任意文字,提交。数字人播报该段文字 diff --git a/app.py b/app.py index cf8380d..bc7a730 100644 --- a/app.py +++ b/app.py @@ -66,7 +66,27 @@ def echo_socket(ws): if len(message)==0: return '输入信息为空' 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(): nerfreal.render() diff --git a/chat.html b/chat.html new file mode 100644 index 0000000..bb117f8 --- /dev/null +++ b/chat.html @@ -0,0 +1,63 @@ + + + + + + + + + + + +
+

WebSocket Test

+
+
+

input text

+ + +
+ +
+
+ +
+ +
+ + + \ No newline at end of file diff --git a/echo.html b/echo.html index a998482..f687c4e 100644 --- a/echo.html +++ b/echo.html @@ -28,7 +28,8 @@