diff --git a/__main__.py b/__main__.py index 2b5706c..3c6d0b8 100644 --- a/__main__.py +++ b/__main__.py @@ -40,9 +40,9 @@ except: print("所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!") # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 -proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, LAYOUT, API_KEY, AVAIL_LLM_MODELS = \ +proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, LAYOUT, API_KEY, AVAIL_LLM_MODELS, LOCAL_PORT= \ get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'LAYOUT', - 'API_KEY', 'AVAIL_LLM_MODELS') + 'API_KEY', 'AVAIL_LLM_MODELS', 'LOCAL_PORT') proxy_info = check_proxy(proxies) # 如果WEB_PORT是-1, 则随机选取WEB端口 @@ -415,7 +415,7 @@ def check_proxy_free(): if __name__ == '__main__': # PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT - PORT = 7891 if WEB_PORT <= 0 else WEB_PORT + PORT = LOCAL_PORT if WEB_PORT <= 0 else WEB_PORT check_proxy_free() ChatBot().main() gr.close_all() diff --git a/docs/assets/custom.css b/docs/assets/custom.css index 6e53450..776127d 100644 --- a/docs/assets/custom.css +++ b/docs/assets/custom.css @@ -8,7 +8,9 @@ --message-bot-background-color-light: #FFFFFF; --message-bot-background-color-dark: #2C2C2C; } - +mspace { + display: block; +} #debug_mes { position: absolute; bottom: 0; diff --git a/func_box.py b/func_box.py index 3b3ea93..7fcc70c 100644 --- a/func_box.py +++ b/func_box.py @@ -131,6 +131,19 @@ def html_tag_color(tag, color=None, font='black'): tag = f' {tag} ' return tag +def html_a_blank(__href, name=''): + if not name: + dir_name = __href + a = f'{name}' + return a + +def html_download_blank(__href, file_name='temp', dir_name=''): + if os.path.exists(__href): + __href = f'/file={__href}' + if not dir_name: + dir_name = file_name + a = f'{file_name}' + return a def ipaddr(): # 获取本地ipx diff --git a/toolbox.py b/toolbox.py index 4ef0e99..1a86b2a 100644 --- a/toolbox.py +++ b/toolbox.py @@ -519,6 +519,7 @@ def get_user_download(chatbot, link, file): """ 将短路径转换为下载链接 """ + file = file.rstrip() for file_handle in str(file).split('\n'): if os.path.isfile(file_handle): # temp_file = func_box.copy_temp_file(file_handle) 无法使用外部的临时目录 @@ -527,19 +528,18 @@ def get_user_download(chatbot, link, file): dir_file, file_name = ('/'.join(str(file_handle).split('/')[-2:]), os.path.basename(file_handle)) chatbot.append(['Convert the file address to a download link at:', f'[Local Message] Successful conversion\n\n ' - f'{file_name}']) + f'{func_box.html_download_blank(__href=temp_file, dir_name=file_name, file_name=file_name)}']) else: chatbot.append(['Convert the file address to a download link at:', f'[Local Message] Conversion failed, file or not exist.']) elif os.path.isdir(file_handle): for root, dirs, files in os.walk(file_handle): for f in files: - temp_ = os.path.abspath(os.path.join(root, f)) - dir_file, file_name = ('/'.join(str(file_handle).split('/')[-2:]), os.path.basename(temp_)) - link_href = f'{link["local"]} / file = {temp_}' + temp_file = os.path.abspath(os.path.join(root, f)) + dir_file, file_name = ('/'.join(str(file_handle).split('/')[-2:]), os.path.basename(temp_file)) chatbot.append(['Convert the file address to a download link at:', f'[Local Message] Successful conversion\n\n ' - f'{func_box.html_a_blank(__href=link_href, dir_name=dir_file, file_name=file_name)}']) + f'{func_box.html_download_blank(__href=temp_file, dir_name=file_name, file_name=file_name)}']) elif file_handle == '': pass return chatbot, ''