import gradio as gr import os import sys import json import requests MODEL =…
- User
import gradio as gr import os import sys import json import requests
MODEL = "gpt-4-1106-preview" API_URL = os.getenv("API_URL") DISABLED = os.getenv("DISABLED") == 'True' OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") print (API_URL) print (OPENAI_API_KEY) NUM_THREADS = int(os.getenv("NUM_THREADS"))
print (NUM_THREADS)
def exception_handler(exception_type, exception, traceback): print("%s: %s" % (exception_type.name, exception)) sys.excepthook = exception_handler sys.tracebacklimit = 0
#https://github.com/gradio-app/gradio/issues/3531#issuecomment-1484029099 def parse_codeblock(text): lines = text.split("\n") for i, line in enumerate(lines): if "
" in line: if line != "": lines[i] = f'' else: lines[i] = '' else: if i > 0: lines[i] = "" + line.replace("<", "<").replace(">", ">") return "".join(lines)def predict(inputs, top_p, temperature, chat_counter, chatbot, history, request:gr.Request): payload = { "model": MODEL, "messages": [{"role": "user", "content": f"{inputs}"}], "temperature" : 1.0, "top_p":1.0, "n" : 1, "stream": True, "presence_penalty":0, "frequency_penalty":0, }
code - Assistant
- User
我想跳过I agree的确认环节,直接进入对话页面,请帮我改好代码
- Assistant
为了跳过用户同意("I agree")的确认环节,直接进入对话页面,你可以按照以下步骤修改代码:
- 去掉与
user_consent_block相关的代码。 - 显示主要的
main_block容器。
下面是修改后的代码部分,仅显示了变更的区域。(注意,省略号
...表示未修改的代码部分保持不变)pythonwith gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;} ...""",theme=theme) as demo: gr.HTML(title) # 省略其他HTML和介绍... with gr.Column(elem_id = "col_container") as main_block: # 主要的交互界面部分,如chatbot, inputs等 chatbot = gr.Chatbot(elem_id='chatbot') inputs = gr.Textbox(placeholder="Hi there!", label="Type an input and press Enter") state = gr.State([]) # s # 省略其他控件,例如按钮和滑动条... # 注释掉 user_consent_block 容器和有关的所有代码 # with gr.Column(elem_id = "user_consent_container") as user_consent_block: # ... # # 更多关于用户同意的代码 # 省略无需更改的inputs.submit和b1.click绑定函数... # 启动并发布应用,省略queue的配置 demo.launch(share=False) - 去掉与
- User
- Assistant
To directly enter the chat interface without the "I agree" confirmation step, you need to remove the user consent code block and automatically display the main block. Here's how you can update the code to do this:
- Remove the
user_consent_blockand its related code. - Ensure the
main_blockis visible (which it is by default, so you can leave as is or explicitly set it to ).
- Remove the