Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -102,15 +102,13 @@ def send_selected_story(title, model_name, system_prompt):
|
|
| 102 |
data = [] # Reset data for new story
|
| 103 |
tokenizer, model = load_model(model_name)
|
| 104 |
selected_story = title
|
| 105 |
-
story_text = ""
|
| 106 |
for story in stories:
|
| 107 |
if story["title"] == title:
|
| 108 |
-
story_text = story['story']
|
| 109 |
system_prompt = f"""
|
| 110 |
{system_prompt}
|
| 111 |
Here is the story:
|
| 112 |
---
|
| 113 |
-
{
|
| 114 |
---
|
| 115 |
"""
|
| 116 |
combined_message = system_prompt.strip()
|
|
@@ -122,7 +120,7 @@ Here is the story:
|
|
| 122 |
question_prompt = "Please ask a simple question about the story to encourage interaction."
|
| 123 |
_, formatted_history, chat_history = interact(question_prompt, chat_history)
|
| 124 |
|
| 125 |
-
return formatted_history, chat_history,
|
| 126 |
else:
|
| 127 |
print("Combined message is empty.")
|
| 128 |
else:
|
|
@@ -160,9 +158,9 @@ def save_comment_score(chat_responses, score, comment, story_name, user_name):
|
|
| 160 |
comment
|
| 161 |
])
|
| 162 |
|
| 163 |
-
#
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "Story Name", "User Input", "Chat Response", "Score", "Comment"])
|
| 168 |
return df, gr.update(value="") # Clear the comment input box
|
|
@@ -183,7 +181,6 @@ with gr.Blocks() as demo:
|
|
| 183 |
system_prompt_input = gr.Textbox(lines=5, value=default_system_prompt, label="System Prompt")
|
| 184 |
|
| 185 |
send_story_button = gr.Button("Send Story")
|
| 186 |
-
story_display = gr.Textbox(label="Selected Story", lines=10, interactive=False)
|
| 187 |
|
| 188 |
with gr.Row():
|
| 189 |
with gr.Column(scale=1):
|
|
@@ -193,6 +190,8 @@ with gr.Blocks() as demo:
|
|
| 193 |
with gr.Column(scale=2):
|
| 194 |
chatbot_output = gr.Chatbot(label="Chat History")
|
| 195 |
|
|
|
|
|
|
|
| 196 |
with gr.Row():
|
| 197 |
with gr.Column(scale=1):
|
| 198 |
score_input = gr.Slider(minimum=0, maximum=5, step=1, label="Score")
|
|
@@ -203,7 +202,7 @@ with gr.Blocks() as demo:
|
|
| 203 |
|
| 204 |
chat_history_json = gr.JSON(value=[], visible=False)
|
| 205 |
|
| 206 |
-
send_story_button.click(fn=send_selected_story, inputs=[story_dropdown, model_dropdown, system_prompt_input], outputs=[chatbot_output, chat_history_json,
|
| 207 |
send_message_button.click(fn=interact, inputs=[chatbot_input, chat_history_json], outputs=[chatbot_input, chatbot_output, chat_history_json])
|
| 208 |
save_button.click(fn=save_comment_score, inputs=[chatbot_output, score_input, comment_input, story_dropdown, user_dropdown], outputs=[data_table, comment_input])
|
| 209 |
|
|
|
|
| 102 |
data = [] # Reset data for new story
|
| 103 |
tokenizer, model = load_model(model_name)
|
| 104 |
selected_story = title
|
|
|
|
| 105 |
for story in stories:
|
| 106 |
if story["title"] == title:
|
|
|
|
| 107 |
system_prompt = f"""
|
| 108 |
{system_prompt}
|
| 109 |
Here is the story:
|
| 110 |
---
|
| 111 |
+
{story['story']}
|
| 112 |
---
|
| 113 |
"""
|
| 114 |
combined_message = system_prompt.strip()
|
|
|
|
| 120 |
question_prompt = "Please ask a simple question about the story to encourage interaction."
|
| 121 |
_, formatted_history, chat_history = interact(question_prompt, chat_history)
|
| 122 |
|
| 123 |
+
return formatted_history, chat_history, gr.update(value=[]) # Reset the data table
|
| 124 |
else:
|
| 125 |
print("Combined message is empty.")
|
| 126 |
else:
|
|
|
|
| 158 |
comment
|
| 159 |
])
|
| 160 |
|
| 161 |
+
# Select the sheet corresponding to the user name
|
| 162 |
+
user_sheet = client.open(google_sheets_name).worksheet(user_name) # Assuming each user has a separate sheet named after them
|
| 163 |
+
user_sheet.append_row([timestamp_str, user_name, model_name, story_name, last_user_message, last_assistant_message, score, comment])
|
| 164 |
|
| 165 |
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "Story Name", "User Input", "Chat Response", "Score", "Comment"])
|
| 166 |
return df, gr.update(value="") # Clear the comment input box
|
|
|
|
| 181 |
system_prompt_input = gr.Textbox(lines=5, value=default_system_prompt, label="System Prompt")
|
| 182 |
|
| 183 |
send_story_button = gr.Button("Send Story")
|
|
|
|
| 184 |
|
| 185 |
with gr.Row():
|
| 186 |
with gr.Column(scale=1):
|
|
|
|
| 190 |
with gr.Column(scale=2):
|
| 191 |
chatbot_output = gr.Chatbot(label="Chat History")
|
| 192 |
|
| 193 |
+
selected_story_output = gr.Textbox(label="Selected Story", interactive=False)
|
| 194 |
+
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column(scale=1):
|
| 197 |
score_input = gr.Slider(minimum=0, maximum=5, step=1, label="Score")
|
|
|
|
| 202 |
|
| 203 |
chat_history_json = gr.JSON(value=[], visible=False)
|
| 204 |
|
| 205 |
+
send_story_button.click(fn=send_selected_story, inputs=[story_dropdown, model_dropdown, system_prompt_input], outputs=[chatbot_output, chat_history_json, data_table, selected_story_output])
|
| 206 |
send_message_button.click(fn=interact, inputs=[chatbot_input, chat_history_json], outputs=[chatbot_input, chatbot_output, chat_history_json])
|
| 207 |
save_button.click(fn=save_comment_score, inputs=[chatbot_output, score_input, comment_input, story_dropdown, user_dropdown], outputs=[data_table, comment_input])
|
| 208 |
|