This commit is contained in:
qingxu fu 2023-07-02 01:05:20 +08:00
parent e11d8132f8
commit a3596ff60d
5 changed files with 58 additions and 4 deletions

1
.gitignore vendored
View File

@ -150,3 +150,4 @@ request_llm/jittorllms
multi-language
request_llm/moss
media
flagged

View File

@ -60,7 +60,9 @@ CONCURRENT_COUNT = 100
AUTO_CLEAR_TXT = False
# 色彩主体,可选: "Default", "Green"
THEME = "Green"
THEME = "Default"
ENABLE_AUDIO = True
# 加一个live2d装饰
ADD_WAIFU = False

View File

@ -0,0 +1,45 @@
from toolbox import update_ui
from toolbox import CatchException, report_execption, write_results_to_file
from crazy_functions.crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
import threading
class InterviewAssistent():
def __init__(self):
pass
# def audio_capture_thread(self):
# 第7步所有线程同时开始执行任务函数
# handles = [ for index, fp in enumerate(file_manifest)]
def init(self):
self.captured_words = ""
# threading.Thread(target=self.audio_capture_thread, args=(self, 1))
def begin(self, llm_kwargs, plugin_kwargs, chatbot, history):
while True:
break
# yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
@CatchException
def 辅助面试(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
pass
# pip install -U openai-whisper
# while True:
# time.sleep(4)
# print(plugin_kwargs)
# ia = InterviewAssistent()
# yield from ia.begin(llm_kwargs, plugin_kwargs, chatbot, history)

10
main.py
View File

@ -6,8 +6,8 @@ def main():
from request_llm.bridge_all import predict
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf, ArgsGeneralWrapper, DummyWith
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = \
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'API_KEY', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT')
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT, ENABLE_AUDIO = \
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'API_KEY', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT', 'ENABLE_AUDIO')
# 如果WEB_PORT是-1, 则随机选取WEB端口
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
@ -57,6 +57,7 @@ def main():
cookies = gr.State({'api_key': API_KEY, 'llm_model': LLM_MODEL})
with gr_L1():
with gr_L2(scale=2):
if ENABLE_AUDIO: audio = gr.Audio(source="microphone", streaming=True)
chatbot = gr.Chatbot(label=f"当前模型:{LLM_MODEL}")
chatbot.style(height=CHATBOT_HEIGHT)
history = gr.State([])
@ -91,7 +92,7 @@ def main():
with gr.Accordion("更多函数插件", open=True):
dropdown_fn_list = [k for k in crazy_fns.keys() if not crazy_fns[k].get("AsButton", True)]
with gr.Row():
dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style(container=False)
dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="", show_label=False).style(container=False)
with gr.Row():
plugin_advanced_arg = gr.Textbox(show_label=True, label="高级参数输入区", visible=False,
placeholder="这里是特殊函数插件的高级参数输入区").style(container=False)
@ -133,6 +134,7 @@ def main():
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2, clearBtn, clearBtn2, plugin_advanced_arg] )
# 整理反复出现的控件句柄组合
input_combo = [cookies, max_length_sl, md_dropdown, txt, txt2, top_p, temperature, chatbot, history, system_prompt, plugin_advanced_arg]
if ENABLE_AUDIO: input_combo.append(audio)
output_combo = [cookies, chatbot, history, status]
predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo)
# 提交按钮、重置按钮
@ -186,6 +188,8 @@ def main():
stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
stopBtn2.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
demo.load()
# gradio的inbrowser触发不太稳定回滚代码到原始的浏览器打开函数
def auto_opentab_delay():
import threading, webbrowser, time

View File

@ -40,6 +40,7 @@ def ArgsGeneralWrapper(f):
"""
装饰器函数用于重组输入参数改变输入参数的顺序与结构
"""
ENABLE_AUDIO, = get_conf('ENABLE_AUDIO')
def decorated(cookies, max_length, llm_model, txt, txt2, top_p, temperature, chatbot, history, system_prompt, plugin_advanced_arg, *args):
txt_passon = txt
if txt == "" and txt2 != "": txt_passon = txt2
@ -58,6 +59,7 @@ def ArgsGeneralWrapper(f):
plugin_kwargs = {
"advanced_arg": plugin_advanced_arg,
}
if ENABLE_AUDIO: plugin_kwargs.update({'audio': args[0]})
chatbot_with_cookie = ChatBotWithCookies(cookies)
chatbot_with_cookie.write_list(chatbot)
yield from f(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, *args)