Skip to content

Commit

Permalink
webui增加聊天输入框及发送按钮;修复webui运行都是b站的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Oct 18, 2023
1 parent 2eeb004 commit 4c0d14b
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def run_external_program():

# 在这里指定要运行的程序和参数
# 例如,运行一个名为 "bilibili.py" 的 Python 脚本
running_process = subprocess.Popen(["python", "bilibili.py"])
running_process = subprocess.Popen(["python", f"{select_platform.value}.py"])

ui.notify("程序开始运行")

Expand Down Expand Up @@ -1434,7 +1434,80 @@ def textarea_data_change(data):
input_talk_baidu_app_id = ui.input(label='AppID', value=config.get("talk", "baidu", "app_id"), placeholder='百度云 语音识别应用的 AppID')
input_talk_baidu_api_key = ui.input(label='API Key', value=config.get("talk", "baidu", "api_key"), placeholder='百度云 语音识别应用的 API Key')
input_talk_baidu_secret_key = ui.input(label='Secret Key', value=config.get("talk", "baidu", "secret_key"), placeholder='百度云 语音识别应用的 Secret Key')
with ui.grid(columns=4):
textarea_talk_chat_box = ui.textarea(label='聊天框', value="", placeholder='此处填写对话内容可以直接进行对话(前面配置好聊天模式,记得运行先)')

'''
聊天页相关的函数
'''

# 发送 聊天框内容
def talk_chat_box_send():
global my_handle, running_flag

if running_flag != 1:
ui.notify("请先点击“一键运行”,然后再进行聊天")
return

if my_handle is None:
from utils.my_handle import My_handle

my_handle = My_handle(config_path)
if my_handle is None:
logging.error("程序初始化失败!")
ui.notify("程序初始化失败!请排查原因")
os._exit(0)

# 获取用户名和文本内容
user_name = input_talk_username.value
content = textarea_talk_chat_box.value

# 清空聊天框
textarea_talk_chat_box.value = ""

data = {
"username": user_name,
"content": content
}

# 正义执行
my_handle.process_data(data, "comment")


# 发送 聊天框内容 进行复读
def talk_chat_box_reread():
global my_handle, running_flag

if my_handle is None:
ui.notify("请先点击“一键运行”,然后再进行聊天")
return

if my_handle is None:
from utils.my_handle import My_handle

my_handle = My_handle(config_path)
if my_handle is None:
logging.error("程序初始化失败!")
ui.notify("程序初始化失败!请排查原因")
os._exit(0)

# 获取用户名和文本内容
user_name = input_talk_username.value
content = textarea_talk_chat_box.value

# 清空聊天框
textarea_talk_chat_box.value = ""

data = {
"username": user_name,
"content": content
}

# 正义执行 直接复读
my_handle.reread_handle(data)

button_talk_chat_box_send = ui.button('发送', on_click=lambda: talk_chat_box_send())
button_talk_chat_box_reread = ui.button('直接复读', on_click=lambda: talk_chat_box_reread())
with ui.tab_panel(docs_page):
ui.label('在线文档:')
ui.link('https://luna.docs.ie.cx/', 'https://luna.docs.ie.cx/', new_tab=True)
Expand Down

0 comments on commit 4c0d14b

Please sign in to comment.