waityousea / xuniren

MIT License
551 stars 159 forks source link

怎么在云端服务器上运行? #8

Open ZJJHYM opened 1 year ago

ZJJHYM commented 1 year ago

我在云端服务器上启动了脚本,python app.py,但是没有任何的显示页面等反应,应该怎么处理呢? image

waityousea commented 1 year ago

在云端启动之后,需要调用接口,传递文本才会有响应。 云端运行,需要将app.py中95行代码中的127.0.0.1的网址改为云端服务器的ip地址,同时还要开启端口,然后将默认端口号8800改为云端服务器开启的端口号:server = pywsgi.WSGIServer(('127.0.0.1', 8800), app, handler_class=WebSocketHandler)

api调用,可以先使用postman进行接口测试,url是POST请求方式,API网址的构成: IP地址:端口号/dighuman 调用API的数据格式为form-data——{question: 问题} 例如下图所示: image

如果返回数据,则表示api测试成功。 其中,视频数据是利用base64进行编码的,所以,想要播放视频,需要将base64格式的视频数据进行解码。

aoyang-hd commented 5 months ago

需要自己写个客户端去请求就行:

from websocket import create_connection
def client_handle():
ws = create_connection('ws://127.0.0.1:8800/dighuman')
while True:
if ws.connected:
ws.send('你好,我叫王尼玛,我来自中国,21岁了')
result = ws.recv()
print(f"client received:{result}")
# ws.close()
if name == "main":
client_handle()