Jithin James commited on
Commit
06d3bc9
·
0 Parent(s):

basic chatbot

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. chatbot-demo.py +44 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__
chatbot-demo.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def get_model_response(user_input, history, user_chats):
5
+ print(user_input, history, user_chats)
6
+ response = f'Hello, you said "{user_input}"'
7
+ history += [user_input, response]
8
+ user_chats.append(user_input)
9
+ responses = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2)]
10
+ return responses, history, user_chats
11
+
12
+
13
+ def clear_chat():
14
+ return [], []
15
+
16
+
17
+ with gr.Blocks() as demo:
18
+ state = gr.State([])
19
+ user_chats = gr.State(value=[])
20
+
21
+ chat = gr.Chatbot()
22
+ with gr.Row():
23
+ with gr.Column(scale=5):
24
+ txt = gr.Textbox(placeholder="Say Hi!", label="press Enter to submit")
25
+ txt.submit(
26
+ get_model_response,
27
+ [txt, state, user_chats],
28
+ [chat, state, user_chats],
29
+ )
30
+ with gr.Column(scale=1, min_width=250):
31
+ choices = ["test"]
32
+ drop_down = gr.Dropdown(label="Clear Till", choices=user_chats.value)
33
+ clear_btn = gr.Button("Clear", label="Clear chat history")
34
+ clear_btn.click(clear_chat, outputs=[state, chat])
35
+
36
+ with gr.Accordion(label="Red-Teaming", open=True):
37
+ gr.Markdown("*instructions on what to do if you break the model*")
38
+ gr.Textbox()
39
+ with gr.Row():
40
+ submit_btn = gr.Button("Submit", label="Submit")
41
+ import_chat_btn = gr.Button("Import Chat", label="import chat")
42
+ export_chat_btn = gr.Button("Export Chat", label="export chat")
43
+
44
+ demo.launch()