rwitz commited on
Commit
30ed04f
1 Parent(s): 64776a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -1
app.py CHANGED
@@ -13,7 +13,25 @@ import sqlite3
13
 
14
  from pymongo.mongo_client import MongoClient
15
  from pymongo.server_api import ServerApi
 
 
 
 
 
 
 
 
 
 
16
 
 
 
 
 
 
 
 
 
17
  password=os.environ.get("MONGODB")
18
  def reset_database():
19
  uri = f"mongodb+srv://new-user:{password}@cluster0.xb2urf6.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
@@ -236,6 +254,13 @@ with gr.Blocks() as demo:
236
  with gr.Row():
237
  submit_btn = gr.Button(value="Send")
238
  reset_btn = gr.Button(value="Reset")
 
 
 
 
 
 
 
239
  reset_btn.click(clear_chat, inputs=[state], outputs=[state, chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
240
  textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b], queue=True)
241
  submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b], queue=True)
@@ -249,7 +274,10 @@ with gr.Blocks() as demo:
249
  direct_textbox = gr.Textbox(placeholder="Enter your message")
250
  direct_submit_btn = gr.Button(value="Send")
251
  direct_reset_btn = gr.Button(value="Reset Chat") # Add this line
252
-
 
 
 
253
  direct_textbox.submit(direct_chat, inputs=[model_dropdown, direct_textbox, direct_chatbot], outputs=[direct_textbox, direct_chatbot])
254
  direct_submit_btn.click(direct_chat, inputs=[model_dropdown, direct_textbox, direct_chatbot], outputs=[direct_textbox, direct_chatbot])
255
  direct_reset_btn.click(reset_direct_chat, None, [direct_textbox, direct_chatbot, model_dropdown])
 
13
 
14
  from pymongo.mongo_client import MongoClient
15
  from pymongo.server_api import ServerApi
16
+ async def direct_regenerate(model, user_input, chatbot):
17
+ temp_state = {
18
+ "history": [
19
+ [{"role": "user", "content": user_input}],
20
+ [{"role": "user", "content": user_input}]
21
+ ]
22
+ }
23
+ response = await get_bot_response(model, user_input, temp_state, 0)
24
+ chatbot[-1] = (user_input, response)
25
+ return "", chatbot
26
 
27
+ async def regenerate_responses(state, chatbot1, chatbot2):
28
+ user_input = state["history"][0][-1]["content"]
29
+ bot1_response = await get_bot_response(state['last_bots'][0], user_input, state, 0)
30
+ bot2_response = await get_bot_response(state['last_bots'][1], user_input, state, 1)
31
+ chatbot1[-1] = (user_input, bot1_response)
32
+ chatbot2[-1] = (user_input, bot2_response)
33
+ return chatbot1, chatbot2
34
+
35
  password=os.environ.get("MONGODB")
36
  def reset_database():
37
  uri = f"mongodb+srv://new-user:{password}@cluster0.xb2urf6.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
 
254
  with gr.Row():
255
  submit_btn = gr.Button(value="Send")
256
  reset_btn = gr.Button(value="Reset")
257
+ with gr.Row():
258
+ submit_btn = gr.Button(value="Send")
259
+ reset_btn = gr.Button(value="Reset")
260
+ regenerate_btn = gr.Button(value="Regenerate")
261
+ # ...
262
+ regenerate_btn.click(regenerate_responses, inputs=[state, chatbot1, chatbot2], outputs=[chatbot1, chatbot2])
263
+
264
  reset_btn.click(clear_chat, inputs=[state], outputs=[state, chatbot1, chatbot2, upvote_btn_a, upvote_btn_b, textbox, submit_btn])
265
  textbox.submit(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b], queue=True)
266
  submit_btn.click(user_ask, inputs=[state, chatbot1, chatbot2, textbox], outputs=[state, chatbot1, chatbot2, textbox, upvote_btn_a, upvote_btn_b], queue=True)
 
274
  direct_textbox = gr.Textbox(placeholder="Enter your message")
275
  direct_submit_btn = gr.Button(value="Send")
276
  direct_reset_btn = gr.Button(value="Reset Chat") # Add this line
277
+ direct_regenerate_btn = gr.Button(value="Regenerate")
278
+ # ...
279
+ direct_regenerate_btn.click(direct_regenerate, inputs=[model_dropdown, direct_textbox, direct_chatbot], outputs=[direct_textbox, direct_chatbot])
280
+
281
  direct_textbox.submit(direct_chat, inputs=[model_dropdown, direct_textbox, direct_chatbot], outputs=[direct_textbox, direct_chatbot])
282
  direct_submit_btn.click(direct_chat, inputs=[model_dropdown, direct_textbox, direct_chatbot], outputs=[direct_textbox, direct_chatbot])
283
  direct_reset_btn.click(reset_direct_chat, None, [direct_textbox, direct_chatbot, model_dropdown])