Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -141,20 +141,8 @@ Here is the story:
|
|
141 |
|
142 |
# Function to save comment and score
|
143 |
def save_comment_score(chat_responses, score, comment, story_name, user_name, system_prompt):
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
# Find the last user and assistant messages
|
148 |
-
for message in reversed(chat_responses):
|
149 |
-
if isinstance(message, list) and len(message) == 2:
|
150 |
-
if message[0] and not last_user_message:
|
151 |
-
last_user_message = message[0]
|
152 |
-
elif message[1] and not last_assistant_message:
|
153 |
-
last_assistant_message = message[1]
|
154 |
-
|
155 |
-
if last_user_message and last_assistant_message:
|
156 |
-
break
|
157 |
-
|
158 |
timestamp = datetime.now(timezone.utc) - timedelta(hours=3) # Adjust to GMT-3
|
159 |
timestamp_str = timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
160 |
model_name = selected_model
|
@@ -166,8 +154,7 @@ def save_comment_score(chat_responses, score, comment, story_name, user_name, sy
|
|
166 |
model_name,
|
167 |
system_prompt,
|
168 |
story_name,
|
169 |
-
|
170 |
-
last_assistant_message,
|
171 |
score,
|
172 |
comment
|
173 |
])
|
@@ -178,10 +165,10 @@ def save_comment_score(chat_responses, score, comment, story_name, user_name, sy
|
|
178 |
except gspread.exceptions.WorksheetNotFound:
|
179 |
user_sheet = client.open(google_sheets_name).add_worksheet(title=user_name, rows="100", cols="20")
|
180 |
|
181 |
-
user_sheet.append_row([timestamp_str, user_name, model_name, system_prompt, story_name,
|
182 |
|
183 |
-
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "System Prompt", "Story Name", "
|
184 |
-
return df[["
|
185 |
|
186 |
# Create the chat interface using Gradio Blocks
|
187 |
with gr.Blocks() as demo:
|
@@ -210,7 +197,7 @@ with gr.Blocks() as demo:
|
|
210 |
score_input = gr.Slider(minimum=0, maximum=5, step=1, label="Score")
|
211 |
comment_input = gr.Textbox(placeholder="Add a comment...", label="Comment")
|
212 |
save_button = gr.Button("Save Score and Comment")
|
213 |
-
data_table = gr.DataFrame(headers=["
|
214 |
|
215 |
with gr.TabItem("User Guide"):
|
216 |
gr.Textbox(label="User Guide", value='''
|
|
|
141 |
|
142 |
# Function to save comment and score
|
143 |
def save_comment_score(chat_responses, score, comment, story_name, user_name, system_prompt):
|
144 |
+
chat_history_str = " ".join([f"{role}: {content}" for role, content in chat_responses])
|
145 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
timestamp = datetime.now(timezone.utc) - timedelta(hours=3) # Adjust to GMT-3
|
147 |
timestamp_str = timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
148 |
model_name = selected_model
|
|
|
154 |
model_name,
|
155 |
system_prompt,
|
156 |
story_name,
|
157 |
+
chat_history_str,
|
|
|
158 |
score,
|
159 |
comment
|
160 |
])
|
|
|
165 |
except gspread.exceptions.WorksheetNotFound:
|
166 |
user_sheet = client.open(google_sheets_name).add_worksheet(title=user_name, rows="100", cols="20")
|
167 |
|
168 |
+
user_sheet.append_row([timestamp_str, user_name, model_name, system_prompt, story_name, chat_history_str, score, comment])
|
169 |
|
170 |
+
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "System Prompt", "Story Name", "Chat History", "Score", "Comment"])
|
171 |
+
return df[["Chat History", "Score", "Comment"]], gr.update(value="") # Show only the required columns and clear the comment input box
|
172 |
|
173 |
# Create the chat interface using Gradio Blocks
|
174 |
with gr.Blocks() as demo:
|
|
|
197 |
score_input = gr.Slider(minimum=0, maximum=5, step=1, label="Score")
|
198 |
comment_input = gr.Textbox(placeholder="Add a comment...", label="Comment")
|
199 |
save_button = gr.Button("Save Score and Comment")
|
200 |
+
data_table = gr.DataFrame(headers=["Chat History", "Score", "Comment"])
|
201 |
|
202 |
with gr.TabItem("User Guide"):
|
203 |
gr.Textbox(label="User Guide", value='''
|