Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -76,6 +76,9 @@ def interact(user_input, history, interaction_count):
|
|
76 |
if tokenizer is None or model is None:
|
77 |
raise ValueError("Tokenizer or model is not initialized.")
|
78 |
|
|
|
|
|
|
|
79 |
messages = history + [{"role": "user", "content": user_input}]
|
80 |
|
81 |
# Ensure roles alternate correctly
|
@@ -92,14 +95,10 @@ def interact(user_input, history, interaction_count):
|
|
92 |
|
93 |
# Update chat history with generated response
|
94 |
history.append({"role": "user", "content": user_input})
|
|
|
95 |
|
96 |
interaction_count += 1
|
97 |
|
98 |
-
if interaction_count >= MAX_INTERACTIONS:
|
99 |
-
response = response.strip() + "\n\nThank you for your questions. Our session is now over. Goodbye!"
|
100 |
-
|
101 |
-
history.append({"role": "assistant", "content": response})
|
102 |
-
|
103 |
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
104 |
|
105 |
return "", formatted_history, history, interaction_count
|
@@ -241,4 +240,4 @@ with gr.Blocks() as demo:
|
|
241 |
send_message_button.click(fn=interact, inputs=[chatbot_input, chat_history_json, interaction_count], outputs=[chatbot_input, chatbot_output, chat_history_json, interaction_count])
|
242 |
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])
|
243 |
|
244 |
-
demo.launch()
|
|
|
76 |
if tokenizer is None or model is None:
|
77 |
raise ValueError("Tokenizer or model is not initialized.")
|
78 |
|
79 |
+
if interaction_count >= MAX_INTERACTIONS:
|
80 |
+
user_input += " Thank you for your questions. Our session is now over. Goodbye!"
|
81 |
+
|
82 |
messages = history + [{"role": "user", "content": user_input}]
|
83 |
|
84 |
# Ensure roles alternate correctly
|
|
|
95 |
|
96 |
# Update chat history with generated response
|
97 |
history.append({"role": "user", "content": user_input})
|
98 |
+
history.append({"role": "assistant", "content": response})
|
99 |
|
100 |
interaction_count += 1
|
101 |
|
|
|
|
|
|
|
|
|
|
|
102 |
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
103 |
|
104 |
return "", formatted_history, history, interaction_count
|
|
|
240 |
send_message_button.click(fn=interact, inputs=[chatbot_input, chat_history_json, interaction_count], outputs=[chatbot_input, chatbot_output, chat_history_json, interaction_count])
|
241 |
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])
|
242 |
|
243 |
+
demo.launch()
|