Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,8 @@ torch.jit.script = lambda f: f
|
|
13 |
# Initialize Google Sheets client
|
14 |
client = init_google_sheets_client()
|
15 |
sheet = client.open(google_sheets_name)
|
16 |
-
stories_sheet = sheet.
|
17 |
-
|
18 |
|
19 |
# Load stories from Google Sheets
|
20 |
def load_stories():
|
@@ -22,16 +22,14 @@ def load_stories():
|
|
22 |
stories = [{"title": story[0], "story": story[1]} for story in stories_data if story[0] != "Title"] # Skip header row
|
23 |
return stories
|
24 |
|
25 |
-
# Load available stories
|
26 |
-
stories = load_stories()
|
27 |
-
|
28 |
# Load system prompts from Google Sheets
|
29 |
def load_system_prompts():
|
30 |
-
|
31 |
-
system_prompts = [
|
32 |
return system_prompts
|
33 |
|
34 |
-
# Load available system prompts
|
|
|
35 |
system_prompts = load_system_prompts()
|
36 |
|
37 |
# Initialize the selected model
|
@@ -130,7 +128,7 @@ Here is the story:
|
|
130 |
question_prompt = "Please ask a simple question about the story to encourage interaction."
|
131 |
_, formatted_history, chat_history = interact(question_prompt, chat_history)
|
132 |
|
133 |
-
return formatted_history, chat_history, gr.update(value=[]),
|
134 |
else:
|
135 |
print("Combined message is empty.")
|
136 |
else:
|
@@ -173,12 +171,8 @@ def save_comment_score(chat_responses, score, comment, story_name, user_name, sy
|
|
173 |
sheet = client.open(google_sheets_name).sheet1 # Assuming results are saved in sheet1
|
174 |
sheet.append_row([timestamp_str, user_name, model_name, system_prompt, story_name, last_user_message, last_assistant_message, score, comment])
|
175 |
|
176 |
-
# Create a DataFrame for display
|
177 |
-
display_data = [[last_user_message, last_assistant_message, score, comment]]
|
178 |
-
df_display = pd.DataFrame(display_data, columns=["User Input", "Chat Response", "Score", "Comment"])
|
179 |
-
|
180 |
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "System Prompt", "Story Name", "User Input", "Chat Response", "Score", "Comment"])
|
181 |
-
return
|
182 |
|
183 |
# Create the chat interface using Gradio Blocks
|
184 |
with gr.Blocks() as demo:
|
@@ -188,10 +182,11 @@ with gr.Blocks() as demo:
|
|
188 |
user_dropdown = gr.Dropdown(choices=user_names, label="Select User Name")
|
189 |
initial_story = stories[0]["title"] if stories else None
|
190 |
story_dropdown = gr.Dropdown(choices=[story["title"] for story in stories], label="Select Story", value=initial_story)
|
191 |
-
|
|
|
192 |
|
193 |
send_story_button = gr.Button("Send Story")
|
194 |
-
|
195 |
|
196 |
with gr.Row():
|
197 |
with gr.Column(scale=1):
|
@@ -211,7 +206,7 @@ with gr.Blocks() as demo:
|
|
211 |
|
212 |
chat_history_json = gr.JSON(value=[], visible=False)
|
213 |
|
214 |
-
send_story_button.click(fn=send_selected_story, inputs=[story_dropdown, model_dropdown, system_prompt_dropdown], outputs=[chatbot_output, chat_history_json, data_table,
|
215 |
send_message_button.click(fn=interact, inputs=[chatbot_input, chat_history_json], outputs=[chatbot_input, chatbot_output, chat_history_json])
|
216 |
save_button.click(fn=save_comment_score, inputs=[chatbot_output, score_input, comment_input, story_dropdown, user_dropdown, system_prompt_dropdown], outputs=[data_table, comment_input])
|
217 |
|
|
|
13 |
# Initialize Google Sheets client
|
14 |
client = init_google_sheets_client()
|
15 |
sheet = client.open(google_sheets_name)
|
16 |
+
stories_sheet = sheet.worksheet("Stories") # Assuming stories are in the second sheet (index 1)
|
17 |
+
system_prompts_sheet = sheet.worksheet("System Prompts") # Assuming system prompts are in a separate sheet
|
18 |
|
19 |
# Load stories from Google Sheets
|
20 |
def load_stories():
|
|
|
22 |
stories = [{"title": story[0], "story": story[1]} for story in stories_data if story[0] != "Title"] # Skip header row
|
23 |
return stories
|
24 |
|
|
|
|
|
|
|
25 |
# Load system prompts from Google Sheets
|
26 |
def load_system_prompts():
|
27 |
+
system_prompts_data = system_prompts_sheet.get_all_values()
|
28 |
+
system_prompts = [prompt[0] for prompt in system_prompts_data if prompt[0] != "System Prompt"] # Skip header row
|
29 |
return system_prompts
|
30 |
|
31 |
+
# Load available stories and system prompts
|
32 |
+
stories = load_stories()
|
33 |
system_prompts = load_system_prompts()
|
34 |
|
35 |
# Initialize the selected model
|
|
|
128 |
question_prompt = "Please ask a simple question about the story to encourage interaction."
|
129 |
_, formatted_history, chat_history = interact(question_prompt, chat_history)
|
130 |
|
131 |
+
return formatted_history, chat_history, gr.update(value=[]), story["story"] # Reset the data table and return the story
|
132 |
else:
|
133 |
print("Combined message is empty.")
|
134 |
else:
|
|
|
171 |
sheet = client.open(google_sheets_name).sheet1 # Assuming results are saved in sheet1
|
172 |
sheet.append_row([timestamp_str, user_name, model_name, system_prompt, story_name, last_user_message, last_assistant_message, score, comment])
|
173 |
|
|
|
|
|
|
|
|
|
174 |
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "System Prompt", "Story Name", "User Input", "Chat Response", "Score", "Comment"])
|
175 |
+
return df[["User Input", "Chat Response", "Score", "Comment"]], gr.update(value="") # Show only the required columns and clear the comment input box
|
176 |
|
177 |
# Create the chat interface using Gradio Blocks
|
178 |
with gr.Blocks() as demo:
|
|
|
182 |
user_dropdown = gr.Dropdown(choices=user_names, label="Select User Name")
|
183 |
initial_story = stories[0]["title"] if stories else None
|
184 |
story_dropdown = gr.Dropdown(choices=[story["title"] for story in stories], label="Select Story", value=initial_story)
|
185 |
+
|
186 |
+
system_prompt_dropdown = gr.Dropdown(choices=system_prompts, label="Select System Prompt")
|
187 |
|
188 |
send_story_button = gr.Button("Send Story")
|
189 |
+
selected_story_textbox = gr.Textbox(label="Selected Story", lines=10, interactive=False)
|
190 |
|
191 |
with gr.Row():
|
192 |
with gr.Column(scale=1):
|
|
|
206 |
|
207 |
chat_history_json = gr.JSON(value=[], visible=False)
|
208 |
|
209 |
+
send_story_button.click(fn=send_selected_story, inputs=[story_dropdown, model_dropdown, system_prompt_dropdown], outputs=[chatbot_output, chat_history_json, data_table, selected_story_textbox])
|
210 |
send_message_button.click(fn=interact, inputs=[chatbot_input, chat_history_json], outputs=[chatbot_input, chatbot_output, chat_history_json])
|
211 |
save_button.click(fn=save_comment_score, inputs=[chatbot_output, score_input, comment_input, story_dropdown, user_dropdown, system_prompt_dropdown], outputs=[data_table, comment_input])
|
212 |
|