vtrv.vls commited on
Commit
df22c76
·
1 Parent(s): 8586e70

Clear inputs on model change

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -46,8 +46,11 @@ def model_gen(content, model_type: str, chat_history):
46
  print(MODEL_LIB[model_type])
47
  return gen(content, chat_history)
48
 
49
- def clear_chat(chatbot, msg):
50
- return [], ''
 
 
 
51
 
52
  MODEL_LIB = {'RUBASE': giga_gen, 'TINYLLAMA': tiny_gen, 'QWEN2INS1B': qwen_gen}
53
 
@@ -66,15 +69,26 @@ def tab_arena():
66
  gradio.Button('Right Better')
67
  gradio.Button('Both Bad')
68
 
69
- with gradio.Accordion("See Details"):
70
- context = gradio.Checkbox(label="No context", value=False)
 
 
 
 
71
 
72
- msg = gradio.Textbox()
73
- clear = gradio.ClearButton([msg, chatbot_left, chatbot_right])
 
 
 
 
 
 
 
74
 
75
  with gradio.Blocks():
76
- model_left.change(clear_chat, [chatbot_left, msg], [chatbot_left, msg])
77
- model_right.change(clear_chat, [chatbot_right, msg], [chatbot_right, msg])
78
  msg.submit(model_gen, [msg, model_left, chatbot_left], [msg, chatbot_left])
79
  msg.submit(model_gen, [msg, model_right, chatbot_right], [msg, chatbot_right])
80
 
 
46
  print(MODEL_LIB[model_type])
47
  return gen(content, chat_history)
48
 
49
+ def clear_chat():
50
+ return '', []
51
+
52
+ def rerun(msg, chatbot):
53
+ return msg, chatbot[:-1]
54
 
55
  MODEL_LIB = {'RUBASE': giga_gen, 'TINYLLAMA': tiny_gen, 'QWEN2INS1B': qwen_gen}
56
 
 
69
  gradio.Button('Right Better')
70
  gradio.Button('Both Bad')
71
 
72
+ with gradio.Row():
73
+ with gradio.Accordion("Parameters", open=False):
74
+ context = gradio.Checkbox(label="No context", value=False)
75
+ top_p = gradio.Slider(label='Top P', minimum=0, maximum=1, value=1, step=0.5)
76
+ temp = gradio.Slider(label='Temperature', minimum=0, maximum=1, value=0.7, step=0.5)
77
+ max_tokens = gradio.Slider(label='Max ouput tokens', minimum=1, maximum=2048, value=512, step=1)
78
 
79
+ with gradio.Row():
80
+ msg = gradio.Textbox()
81
+
82
+ with gradio.Row():
83
+ clear = gradio.ClearButton([msg, chatbot_left, chatbot_right], value='Clear history')
84
+ regen_left = gradio.Button(value='Regenerate left answer')
85
+ regen_right = gradio.Button(value='Regenerate right answer')
86
+ regen_left.click(rerun, [msg, chatbot_left], [msg, chatbot_left])
87
+ regen_right.click(rerun, [msg, chatbot_right], [msg, chatbot_left])
88
 
89
  with gradio.Blocks():
90
+ model_left.change(clear_chat, [], [msg, chatbot_left])
91
+ model_right.change(clear_chat, [], [msg, chatbot_right])
92
  msg.submit(model_gen, [msg, model_left, chatbot_left], [msg, chatbot_left])
93
  msg.submit(model_gen, [msg, model_right, chatbot_right], [msg, chatbot_right])
94