Nol00 commited on
Commit
31b6d03
·
verified ·
1 Parent(s): 810de64

Update crs_arena/arena.py

Browse files
Files changed (1) hide show
  1. crs_arena/arena.py +67 -109
crs_arena/arena.py CHANGED
@@ -205,6 +205,71 @@ def feedback_dialog(row_id: int) -> None:
205
  st.session_state.clear()
206
  st.rerun()
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  # Streamlit app
209
  st.set_page_config(page_title="CRS Arena", layout="wide")
210
 
@@ -260,118 +325,11 @@ col_crs1, col_crs2 = st.columns(2)
260
 
261
  # CRS 1
262
  with col_crs1:
263
- with st.container(border=True):
264
- st.write(":red_circle: CRS 1")
265
- # Display the chat history
266
- messages_crs1 = st.container(height=350, border=False)
267
- for message in st.session_state["messages_1"]:
268
- messages_crs1.chat_message(message["role"]).write(
269
- message["message"]
270
- )
271
-
272
- if prompt1 := st.chat_input(
273
- "Send a message to CRS 1",
274
- key="prompt_crs1",
275
- disabled=not st.session_state["crs1_enabled"],
276
- ):
277
- # Display the user's message
278
- messages_crs1.chat_message("user").write(prompt1)
279
-
280
- # Add user's message to chat history
281
- st.session_state["messages_1"].append(
282
- {"role": "user", "message": prompt1}
283
- )
284
- # Get the CRS response
285
- response_crs1 = messages_crs1.chat_message(
286
- "assistant"
287
- ).write_stream(get_crs_response(st.session_state["crs1"], prompt1))
288
-
289
- # Add CRS response to chat history
290
- st.session_state["messages_1"].append(
291
- {"role": "assistant", "message": response_crs1}
292
- )
293
-
294
- crs1_frustrated_col, crs1_satisfied_col = st.columns(2)
295
- crs1_frustrated_col.button(
296
- ":rage: Frustrated",
297
- use_container_width=True,
298
- key="end_frustated_crs1",
299
- on_click=end_conversation,
300
- kwargs={
301
- "crs": st.session_state["crs1"],
302
- "sentiment": "frustrated",
303
- },
304
- disabled=not st.session_state["crs1_enabled"],
305
- )
306
- crs1_satisfied_col.button(
307
- ":heavy_check_mark: Satisfied",
308
- use_container_width=True,
309
- key="end_satisfied_crs1",
310
- on_click=end_conversation,
311
- kwargs={
312
- "crs": st.session_state["crs1"],
313
- "sentiment": "satisfied",
314
- },
315
- disabled=not st.session_state["crs1_enabled"],
316
- )
317
 
318
  # CRS 2
319
  with col_crs2:
320
- with st.container(border=True):
321
- st.write(":large_blue_circle: CRS 2")
322
- # Display the chat history
323
- messages_crs2 = st.container(height=350, border=False)
324
- for message in st.session_state["messages_2"]:
325
- messages_crs2.chat_message(message["role"]).write(
326
- message["message"]
327
- )
328
-
329
- if prompt2 := st.chat_input(
330
- "Send a message to CRS 2",
331
- key="prompt_crs2",
332
- disabled=not st.session_state["crs2_enabled"],
333
- ):
334
- # Display the user's message
335
- messages_crs2.chat_message("user").write(prompt2)
336
-
337
- # Add user's message to chat history
338
- st.session_state["messages_2"].append(
339
- {"role": "user", "message": prompt2}
340
- )
341
-
342
- # Get the CRS response
343
- response_crs2 = messages_crs2.chat_message(
344
- "assistant"
345
- ).write_stream(get_crs_response(st.session_state["crs2"], prompt2))
346
-
347
- # Add CRS response to chat history
348
- st.session_state["messages_2"].append(
349
- {"role": "assistant", "message": response_crs2}
350
- )
351
-
352
- crs2_frustrated_col, crs2_satisfied_col = st.columns(2)
353
- crs2_frustrated_col.button(
354
- ":rage: Frustrated",
355
- use_container_width=True,
356
- key="end_frustated_crs2",
357
- on_click=end_conversation,
358
- kwargs={
359
- "crs": st.session_state["crs2"],
360
- "sentiment": "frustrated",
361
- },
362
- disabled=not st.session_state["crs2_enabled"],
363
- )
364
- crs2_satisfied_col.button(
365
- ":heavy_check_mark: Satisfied",
366
- use_container_width=True,
367
- key="end_satisfied_crs2",
368
- on_click=end_conversation,
369
- kwargs={
370
- "crs": st.session_state["crs2"],
371
- "sentiment": "satisfied",
372
- },
373
- disabled=not st.session_state["crs2_enabled"],
374
- )
375
 
376
  # Feedback section
377
  container = st.container()
 
205
  st.session_state.clear()
206
  st.rerun()
207
 
208
+ @st.fragment
209
+ def chat_col(crs_id: int, color: str):
210
+ """Chat column for the CRS model.
211
+
212
+ Args:
213
+ crs_id: CRS model ID (either 1 or 2).
214
+ color: Color of the CRS model (red or large_blue).
215
+ """
216
+ with st.container(border=True):
217
+ st.write(f":{color}_circle: CRS {crs_id}")
218
+ # Display the chat history
219
+ messages_crs = st.container(height=350, border=False)
220
+ for message in st.session_state[f"messages_{crs_id}"]:
221
+ messages_crs.chat_message(message["role"]).write(
222
+ message["message"]
223
+ )
224
+
225
+ if prompt := st.chat_input(
226
+ f"Send a message to CRS {crs_id}",
227
+ key=f"prompt_crs{crs_id}",
228
+ disabled=not st.session_state[f"crs{crs_id}_enabled"],
229
+ ):
230
+ # Display the user's message
231
+ messages_crs.chat_message("user").write(prompt)
232
+ # Add user's message to chat history
233
+ st.session_state[f"messages_{crs_id}"].append(
234
+ {"role": "user", "message": prompt}
235
+ )
236
+ # Get the CRS response
237
+ response_crs = messages_crs.chat_message("assistant").write_stream(
238
+ get_crs_response(st.session_state[f"crs{crs_id}"], prompt)
239
+ )
240
+
241
+ # Add CRS response to chat history
242
+ st.session_state[f"messages_{crs_id}"].append(
243
+ {"role": "assistant", "message": response_crs}
244
+ )
245
+
246
+ frustrated_col, satisfied_col = st.columns(2)
247
+ if frustrated_col.button(
248
+ ":rage: Frustrated",
249
+ use_container_width=True,
250
+ key=f"end_frustated_crs{crs_id}",
251
+ on_click=end_conversation,
252
+ kwargs={
253
+ "crs": st.session_state[f"crs{crs_id}"],
254
+ "sentiment": "frustrated",
255
+ },
256
+ disabled=not st.session_state[f"crs{crs_id}_enabled"],
257
+ ):
258
+ st.rerun()
259
+ if satisfied_col.button(
260
+ ":heavy_check_mark: Satisfied",
261
+ use_container_width=True,
262
+ key=f"end_satisfied_crs{crs_id}",
263
+ on_click=end_conversation,
264
+ kwargs={
265
+ "crs": st.session_state[f"crs{crs_id}"],
266
+ "sentiment": "satisfied",
267
+ },
268
+ disabled=not st.session_state[f"crs{crs_id}_enabled"],
269
+ ):
270
+ st.rerun()
271
+
272
+
273
  # Streamlit app
274
  st.set_page_config(page_title="CRS Arena", layout="wide")
275
 
 
325
 
326
  # CRS 1
327
  with col_crs1:
328
+ chat_col(1, "red")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
 
330
  # CRS 2
331
  with col_crs2:
332
+ chat_col(2, "large_blue")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
  # Feedback section
335
  container = st.container()