From c9f68cf39a63660e831310675d7a8f8ba934fbd2 Mon Sep 17 00:00:00 2001 From: Bluzy Date: Fri, 7 Apr 2023 11:19:43 +0800 Subject: [PATCH] update web_demo --- web_demo.py | 2 +- web_demo2.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/web_demo.py b/web_demo.py index 88a6dc8..522a4bd 100644 --- a/web_demo.py +++ b/web_demo.py @@ -42,4 +42,4 @@ with gr.Blocks() as demo: temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True) button = gr.Button("Generate") button.click(predict, [txt, max_length, top_p, temperature, state], [state] + text_boxes) -demo.queue().launch(share=False, inbrowser=True) +demo.queue().launch(server_port=6006, server_name='0.0.0.0', share=False, inbrowser=True) diff --git a/web_demo2.py b/web_demo2.py index 4e1f0e4..226682e 100644 --- a/web_demo2.py +++ b/web_demo2.py @@ -21,7 +21,7 @@ MAX_TURNS = 20 MAX_BOXES = MAX_TURNS * 2 -def predict(input, history=None): +def predict(input, max_length, top_p, temperature, history=None): tokenizer, model = get_model() if history is None: history = [] @@ -35,7 +35,8 @@ def predict(input, history=None): message(input, avatar_style="big-smile", key=str(len(history)) + "_user") st.write("AI正在回复:") with st.empty(): - for response, history in model.stream_chat(tokenizer, input, history): + for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p, + temperature=temperature): query, response = history[-1] st.write(response) @@ -49,6 +50,15 @@ prompt_text = st.text_area(label="用户命令输入", height = 100, placeholder="请在这儿输入您的命令") +max_length = st.sidebar.slider( + 'max_length', 0, 4096, 2048, step=1 +) +top_p = st.sidebar.slider( + 'top_p', 0.0, 1.0, 0.6, step=0.01 +) +temperature = st.sidebar.slider( + 'temperature', 0.0, 1.0, 0.95, step=0.01 +) if 'state' not in st.session_state: st.session_state['state'] = [] @@ -56,4 +66,4 @@ if 'state' not in st.session_state: if st.button("发送", key="predict"): with st.spinner("AI正在思考,请稍等........"): # text generation - st.session_state["state"] = predict(prompt_text, st.session_state["state"]) + st.session_state["state"] = predict(prompt_text, max_length, top_p, temperature, st.session_state["state"]) \ No newline at end of file