Spaces:
Runtime error
Runtime error
import gradio as gr | |
def get_model_response(user_input, history, user_chats): | |
print(user_input, history, user_chats) | |
response = f'Hello, you said "{user_input}"' | |
history += [user_input, response] | |
user_chats.append(user_input) | |
responses = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)] | |
return responses, history, user_chats | |
def clear_chat(): | |
return [], [] | |
with gr.Blocks() as demo: | |
state = gr.State([]) | |
user_chats = gr.State(value=[]) | |
chat = gr.Chatbot() | |
with gr.Row(): | |
with gr.Column(scale=5): | |
txt = gr.Textbox(placeholder="Say Hi!", label="press Enter to submit") | |
txt.submit( | |
get_model_response, | |
[txt, state, user_chats], | |
[chat, state, user_chats], | |
) | |
with gr.Column(scale=1, min_width=250): | |
choices = ["test"] | |
drop_down = gr.Dropdown(label="Clear Till", choices=user_chats.value) | |
clear_btn = gr.Button("Clear", label="Clear chat history") | |
clear_btn.click(clear_chat, outputs=[state, chat]) | |
with gr.Accordion(label="Red-Teaming", open=True): | |
gr.Markdown("*instructions on what to do if you break the model*") | |
gr.Textbox() | |
with gr.Row(): | |
submit_btn = gr.Button("Submit", label="Submit") | |
import_chat_btn = gr.Button("Import Chat", label="import chat") | |
export_chat_btn = gr.Button("Export Chat", label="export chat") | |
demo.launch() | |