luminoussg commited on
Commit
27ecf43
·
verified ·
1 Parent(s): 9b382da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -128,12 +128,21 @@ with gr.Blocks() as demo:
128
 
129
  chatbot = gr.Chatbot(height=600)
130
  msg = gr.Textbox(label="Message")
 
131
 
132
  def on_new_session():
133
  new_id = session_manager.create_session()
134
  return new_id, []
135
 
136
- def user(message, history, session_id):
 
 
 
 
 
 
 
 
137
  return "", history + [[message, None]]
138
 
139
  def bot(history, session_id):
@@ -143,7 +152,7 @@ with gr.Blocks() as demo:
143
  history[-1][1] = response
144
  yield history
145
 
146
- msg.submit(user, [msg, chatbot, session_id], [msg, chatbot]).then(
147
  bot, [chatbot, session_id], [chatbot]
148
  )
149
  new_session.click(on_new_session, None, [session_id, chatbot])
 
128
 
129
  chatbot = gr.Chatbot(height=600)
130
  msg = gr.Textbox(label="Message")
131
+ save_history = gr.Checkbox(label="Save Conversation History", value=True)
132
 
133
  def on_new_session():
134
  new_id = session_manager.create_session()
135
  return new_id, []
136
 
137
+ def user(message, history, session_id, save_history):
138
+ if save_history:
139
+ session = session_manager.load_session(session_id)
140
+ session["history"].append({
141
+ "timestamp": datetime.now().isoformat(),
142
+ "type": "user",
143
+ "content": message
144
+ })
145
+ session_manager.save_session(session_id, session)
146
  return "", history + [[message, None]]
147
 
148
  def bot(history, session_id):
 
152
  history[-1][1] = response
153
  yield history
154
 
155
+ msg.submit(user, [msg, chatbot, session_id, save_history], [msg, chatbot]).then(
156
  bot, [chatbot, session_id], [chatbot]
157
  )
158
  new_session.click(on_new_session, None, [session_id, chatbot])