hanzla javaid commited on
Commit
e9d2334
Β·
1 Parent(s): 97e6085
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -37,10 +37,9 @@ def chat(message, history, model1, model2):
37
 
38
  def vote(direction, history):
39
  if history:
40
- last_interaction = history[-1]
41
  vote_text = f"\n\nUser voted: {'πŸ‘' if direction == 'up' else 'πŸ‘Ž'}"
42
- updated_interaction = (last_interaction[0], last_interaction[1] + vote_text)
43
- return history[:-1] + [updated_interaction]
44
  return history
45
 
46
 
@@ -51,7 +50,7 @@ with gr.Blocks() as demo:
51
  model1_dropdown = gr.Dropdown(choices=models, label="Model 1", value=models[0])
52
  model2_dropdown = gr.Dropdown(choices=models, label="Model 2", value=models[1])
53
 
54
- chatbot = gr.Chatbot()
55
  msg = gr.Textbox(label="Your message")
56
  clear = gr.Button("Clear")
57
 
@@ -60,7 +59,7 @@ with gr.Blocks() as demo:
60
  downvote = gr.Button("πŸ‘Ž Downvote")
61
 
62
  msg.submit(chat, [msg, chatbot, model1_dropdown, model2_dropdown], chatbot)
63
- clear.click(lambda: None, None, chatbot, queue=False)
64
  upvote.click(vote, ["up", chatbot], chatbot)
65
  downvote.click(vote, ["down", chatbot], chatbot)
66
 
 
37
 
38
  def vote(direction, history):
39
  if history:
40
+ last_message = history[-1]
41
  vote_text = f"\n\nUser voted: {'πŸ‘' if direction == 'up' else 'πŸ‘Ž'}"
42
+ last_message["content"] += vote_text
 
43
  return history
44
 
45
 
 
50
  model1_dropdown = gr.Dropdown(choices=models, label="Model 1", value=models[0])
51
  model2_dropdown = gr.Dropdown(choices=models, label="Model 2", value=models[1])
52
 
53
+ chatbot = gr.Chatbot(label="Chat History", type="messages")
54
  msg = gr.Textbox(label="Your message")
55
  clear = gr.Button("Clear")
56
 
 
59
  downvote = gr.Button("πŸ‘Ž Downvote")
60
 
61
  msg.submit(chat, [msg, chatbot, model1_dropdown, model2_dropdown], chatbot)
62
+ clear.click(lambda: [], None, chatbot, queue=False)
63
  upvote.click(vote, ["up", chatbot], chatbot)
64
  downvote.click(vote, ["down", chatbot], chatbot)
65