zhiminy commited on
Commit
17322b6
·
1 Parent(s): 946d041

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -18
app.py CHANGED
@@ -266,7 +266,9 @@ def chat_with_models(model_alias, models, conversation_state, timeout=TIMEOUT):
266
  )
267
 
268
  # Format the complete conversation history with different colors
269
- formatted_history = format_conversation_history(conversation_state[model_key][1:])
 
 
270
 
271
  return formatted_history
272
 
@@ -294,7 +296,7 @@ def format_conversation_history(conversation_history):
294
  return formatted_text
295
 
296
 
297
- def save_content_to_hf(feedback_data, repo_name):
298
  """
299
  Save feedback content to Hugging Face repository organized by quarter.
300
  """
@@ -304,14 +306,8 @@ def save_content_to_hf(feedback_data, repo_name):
304
  # Create a binary file-like object
305
  file_like_object = io.BytesIO(json_content)
306
 
307
- # Get the current year and quarter
308
- now = datetime.now()
309
- quarter = (now.month - 1) // 3 + 1
310
- year_quarter = f"{now.year}_Q{quarter}"
311
- timestamp = now.strftime("%Y%m%d_%H%M%S")
312
-
313
  # Define the path in the repository
314
- filename = f"{year_quarter}/{timestamp}.json"
315
 
316
  # Ensure the user is authenticated with HF
317
  token = HfFolder.get_token()
@@ -779,11 +775,13 @@ with gr.Blocks() as app:
779
 
780
  # Create a copy to avoid modifying the original
781
  conversations = models.copy()
782
- conversations.update({
783
- "url": repo_url,
784
- "left_chat": [{"role": "user", "content": combined_user_input}],
785
- "right_chat": [{"role": "user", "content": combined_user_input}]
786
- })
 
 
787
 
788
  # Clear previous states
789
  models_state.clear()
@@ -1006,7 +1004,9 @@ with gr.Blocks() as app:
1006
  # Handle subsequent rounds
1007
  def handle_model_a_send(user_input, models_state, conversation_state):
1008
  try:
1009
- conversation_state["left_chat"].append({"role": "user", "content": user_input})
 
 
1010
  response = chat_with_models("left", models_state, conversation_state)
1011
  # Clear the input box and disable the send button
1012
  return (
@@ -1045,7 +1045,9 @@ with gr.Blocks() as app:
1045
 
1046
  def handle_model_b_send(user_input, models_state, conversation_state):
1047
  try:
1048
- conversation_state["right_chat"].append({"role": "user", "content": user_input})
 
 
1049
  response = chat_with_models("right", models_state, conversation_state)
1050
  # Clear the input box and disable the send button
1051
  return (
@@ -1121,8 +1123,14 @@ with gr.Blocks() as app:
1121
  "winner": winner_model,
1122
  }
1123
 
 
 
 
 
 
 
1124
  # Save feedback back to the Hugging Face dataset
1125
- save_content_to_hf(feedback_entry, "SE-Arena/votes")
1126
 
1127
  conversation_state["right_chat"][0]["content"] = conversation_state[
1128
  "right_chat"
@@ -1132,7 +1140,9 @@ with gr.Blocks() as app:
1132
  ][0]["content"].split("\n\nInquiry: ")[-1]
1133
 
1134
  # Save conversations back to the Hugging Face dataset
1135
- save_content_to_hf(conversation_state, "SE-Arena/conversations")
 
 
1136
 
1137
  # Clear state
1138
  models_state.clear()
 
266
  )
267
 
268
  # Format the complete conversation history with different colors
269
+ formatted_history = format_conversation_history(
270
+ conversation_state[model_key][1:]
271
+ )
272
 
273
  return formatted_history
274
 
 
296
  return formatted_text
297
 
298
 
299
+ def save_content_to_hf(feedback_data, repo_name, folder_name, file_name):
300
  """
301
  Save feedback content to Hugging Face repository organized by quarter.
302
  """
 
306
  # Create a binary file-like object
307
  file_like_object = io.BytesIO(json_content)
308
 
 
 
 
 
 
 
309
  # Define the path in the repository
310
+ filename = f"{folder_name}/{file_name}.json"
311
 
312
  # Ensure the user is authenticated with HF
313
  token = HfFolder.get_token()
 
775
 
776
  # Create a copy to avoid modifying the original
777
  conversations = models.copy()
778
+ conversations.update(
779
+ {
780
+ "url": repo_url,
781
+ "left_chat": [{"role": "user", "content": combined_user_input}],
782
+ "right_chat": [{"role": "user", "content": combined_user_input}],
783
+ }
784
+ )
785
 
786
  # Clear previous states
787
  models_state.clear()
 
1004
  # Handle subsequent rounds
1005
  def handle_model_a_send(user_input, models_state, conversation_state):
1006
  try:
1007
+ conversation_state["left_chat"].append(
1008
+ {"role": "user", "content": user_input}
1009
+ )
1010
  response = chat_with_models("left", models_state, conversation_state)
1011
  # Clear the input box and disable the send button
1012
  return (
 
1045
 
1046
  def handle_model_b_send(user_input, models_state, conversation_state):
1047
  try:
1048
+ conversation_state["right_chat"].append(
1049
+ {"role": "user", "content": user_input}
1050
+ )
1051
  response = chat_with_models("right", models_state, conversation_state)
1052
  # Clear the input box and disable the send button
1053
  return (
 
1123
  "winner": winner_model,
1124
  }
1125
 
1126
+ # Get the current year and quarter
1127
+ now = datetime.now()
1128
+ quarter = (now.month - 1) // 3 + 1
1129
+ folder_name = f"{now.year}_Q{quarter}"
1130
+ file_name = now.strftime("%Y%m%d_%H%M%S")
1131
+
1132
  # Save feedback back to the Hugging Face dataset
1133
+ save_content_to_hf(feedback_entry, "SE-Arena/votes", folder_name, file_name)
1134
 
1135
  conversation_state["right_chat"][0]["content"] = conversation_state[
1136
  "right_chat"
 
1140
  ][0]["content"].split("\n\nInquiry: ")[-1]
1141
 
1142
  # Save conversations back to the Hugging Face dataset
1143
+ save_content_to_hf(
1144
+ conversation_state, "SE-Arena/conversations", folder_name, file_name
1145
+ )
1146
 
1147
  # Clear state
1148
  models_state.clear()