import random import gradio as gr def chat(message, history): history = history or [] message = message.lower() if message.startswith("how many"): response = random.randint(1, 10)+"d" elif message.startswith("how"): response = random.choice(["Great", "Good", "Okay", "Bad"]) elif message.startswith("where"): response = random.choice(["Here", "There", "Somewhere"]) else: response = "I don't know" history.append((message, response)) return history, history import random import gradio as gr import time def echo(message, history, system_prompt, tokens): response = f"System prompt: {system_prompt}\n Message: {message}." for i in range(min(len(response), int(tokens))): time.sleep(0.05) yield response[: i+1] with gr.Blocks() as demo: system_prompt = gr.Textbox("You are helpful AI.", label="System Prompt") slider = gr.Slider(10, 100, render=False) gr.ChatInterface( echo, additional_inputs=[system_prompt, slider] ) demo.queue().launch() # # 设置一个对话窗 # chatbot = gr.Chatbot() # demo = gr.Interface( # chat, # # 添加state组件 # ["text", "state"], # [chatbot, "state"], # # 设置没有保存数据的按钮 # allow_flagging="never", # ) # demo.launch() # demo.launch(share=True,server_port=8080,server_name="0.0.0.0") print("運行成功了")