File size: 1,515 Bytes
06d3bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()