Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,10 +106,12 @@ def interact(user_input, history):
|
|
| 106 |
def send_selected_story(title, model_name, system_prompt):
|
| 107 |
global chat_history
|
| 108 |
global selected_story
|
|
|
|
| 109 |
global data # Ensure data is reset
|
| 110 |
data = [] # Reset data for new story
|
| 111 |
tokenizer, model = load_model(model_name)
|
| 112 |
selected_story = title
|
|
|
|
| 113 |
for story in stories:
|
| 114 |
if story["title"] == title:
|
| 115 |
system_prompt = f"""
|
|
@@ -153,12 +155,14 @@ def save_comment_score(chat_responses, score, comment, story_name, user_name):
|
|
| 153 |
timestamp = datetime.now(timezone.utc) - timedelta(hours=3) # Adjust to GMT-3
|
| 154 |
timestamp_str = timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
| 155 |
model_name = selected_model
|
|
|
|
| 156 |
|
| 157 |
# Append data to local data storage
|
| 158 |
data.append([
|
| 159 |
timestamp_str,
|
| 160 |
user_name,
|
| 161 |
model_name,
|
|
|
|
| 162 |
story_name,
|
| 163 |
last_user_message,
|
| 164 |
last_assistant_message,
|
|
@@ -168,9 +172,9 @@ def save_comment_score(chat_responses, score, comment, story_name, user_name):
|
|
| 168 |
|
| 169 |
# Append data to Google Sheets
|
| 170 |
sheet = client.open(google_sheets_name).worksheet(user_name) # Save to user-specific sheet
|
| 171 |
-
sheet.append_row([timestamp_str, user_name, model_name, story_name, last_user_message, last_assistant_message, score, comment])
|
| 172 |
|
| 173 |
-
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "Story Name", "User Input", "Chat Response", "Score", "Comment"])
|
| 174 |
return df, gr.update(value="") # Clear the comment input box
|
| 175 |
|
| 176 |
# Create the chat interface using Gradio Blocks
|
|
@@ -200,7 +204,7 @@ with gr.Blocks() as demo:
|
|
| 200 |
comment_input = gr.Textbox(placeholder="Add a comment...", label="Comment")
|
| 201 |
save_button = gr.Button("Save Score and Comment")
|
| 202 |
|
| 203 |
-
data_table = gr.DataFrame(headers=["Timestamp", "User Name", "Model Name", "Story Name", "User Input", "Chat Response", "Score", "Comment"], visible=True)
|
| 204 |
|
| 205 |
chat_history_json = gr.JSON(value=[], visible=False)
|
| 206 |
|
|
|
|
| 106 |
def send_selected_story(title, model_name, system_prompt):
|
| 107 |
global chat_history
|
| 108 |
global selected_story
|
| 109 |
+
global selected_system_prompt
|
| 110 |
global data # Ensure data is reset
|
| 111 |
data = [] # Reset data for new story
|
| 112 |
tokenizer, model = load_model(model_name)
|
| 113 |
selected_story = title
|
| 114 |
+
selected_system_prompt = system_prompt
|
| 115 |
for story in stories:
|
| 116 |
if story["title"] == title:
|
| 117 |
system_prompt = f"""
|
|
|
|
| 155 |
timestamp = datetime.now(timezone.utc) - timedelta(hours=3) # Adjust to GMT-3
|
| 156 |
timestamp_str = timestamp.strftime("%Y-%m-%d %H:%M:%S")
|
| 157 |
model_name = selected_model
|
| 158 |
+
system_prompt = selected_system_prompt
|
| 159 |
|
| 160 |
# Append data to local data storage
|
| 161 |
data.append([
|
| 162 |
timestamp_str,
|
| 163 |
user_name,
|
| 164 |
model_name,
|
| 165 |
+
system_prompt,
|
| 166 |
story_name,
|
| 167 |
last_user_message,
|
| 168 |
last_assistant_message,
|
|
|
|
| 172 |
|
| 173 |
# Append data to Google Sheets
|
| 174 |
sheet = client.open(google_sheets_name).worksheet(user_name) # Save to user-specific sheet
|
| 175 |
+
sheet.append_row([timestamp_str, user_name, model_name, system_prompt, story_name, last_user_message, last_assistant_message, score, comment])
|
| 176 |
|
| 177 |
+
df = pd.DataFrame(data, columns=["Timestamp", "User Name", "Model Name", "System Prompt", "Story Name", "User Input", "Chat Response", "Score", "Comment"])
|
| 178 |
return df, gr.update(value="") # Clear the comment input box
|
| 179 |
|
| 180 |
# Create the chat interface using Gradio Blocks
|
|
|
|
| 204 |
comment_input = gr.Textbox(placeholder="Add a comment...", label="Comment")
|
| 205 |
save_button = gr.Button("Save Score and Comment")
|
| 206 |
|
| 207 |
+
data_table = gr.DataFrame(headers=["Timestamp", "User Name", "Model Name", "System Prompt", "Story Name", "User Input", "Chat Response", "Score", "Comment"], visible=True)
|
| 208 |
|
| 209 |
chat_history_json = gr.JSON(value=[], visible=False)
|
| 210 |
|