Corianas commited on
Commit
aaae854
1 Parent(s): 01a82e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -26
app.py CHANGED
@@ -105,30 +105,27 @@ def gen(input):
105
  return input + out
106
 
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  with gr.Blocks() as demo:
109
- chatbot = gr.Chatbot()
110
- msg = gr.Textbox()
111
- clear = gr.Button("Clear")
112
-
113
- def user(user_message, history):
114
- return gr.update(value="", interactive=False), history + [[user_message, None]]
115
-
116
- def bot(history):
117
- # Generate the bot's response using your model
118
- input_text = history[-1][0]
119
- bot_message = gen(input_text)
120
-
121
- history[-1][1] = ""
122
- for character in bot_message:
123
- history[-1][1] += character
124
- time.sleep(0.05)
125
- yield history
126
-
127
- response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
128
- bot, chatbot, chatbot
129
- )
130
- response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
131
- clear.click(lambda: None, None, chatbot, queue=False)
132
-
133
- demo.queue()
134
- demo.launch()
 
105
  return input + out
106
 
107
 
108
+ def chatbot_func(user_message, history):
109
+ history = history + [[user_message, None]]
110
+ bot_message = gen(user_message)
111
+
112
+ for character in bot_message:
113
+ history[-1][1] += character
114
+ time.sleep(0.05)
115
+
116
+ return history
117
+
118
+ def clear_chatbot(clear, history):
119
+ return [] if clear else history
120
+
121
  with gr.Blocks() as demo:
122
+ chatbot = gr.Chatbot(callback=chatbot_func, default=[[None, "Hi! I'm your ChatGPT bot. How can I assist you today?"]])
123
+ clear = gr.Button("Clear", label="Clear Chat")
124
+
125
+ clear.set_observer(clear_chatbot, [clear, chatbot])
126
+
127
+ demo.add(chatbot, clear)
128
+ demo.launch()
129
+
130
+
131
+