Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -76,17 +76,6 @@ 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 |
-
# Increment interaction count
|
80 |
-
interaction_count += 1
|
81 |
-
print(f"Interaction count: {interaction_count}") # Print the interaction count
|
82 |
-
|
83 |
-
# Check if the maximum number of interactions has been reached
|
84 |
-
if interaction_count > MAX_INTERACTIONS:
|
85 |
-
farewell_message = "Thank you for the conversation! Have a great day!"
|
86 |
-
history.append({"role": "assistant", "content": farewell_message})
|
87 |
-
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
88 |
-
return "", formatted_history, history, interaction_count
|
89 |
-
|
90 |
messages = history + [{"role": "user", "content": user_input}]
|
91 |
|
92 |
# Ensure roles alternate correctly
|
@@ -104,6 +93,13 @@ def interact(user_input, history, interaction_count):
|
|
104 |
# Update chat history with generated response
|
105 |
history.append({"role": "user", "content": user_input})
|
106 |
history.append({"role": "assistant", "content": response})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
109 |
return "", formatted_history, 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
|
|
|
93 |
# Update chat history with generated response
|
94 |
history.append({"role": "user", "content": user_input})
|
95 |
history.append({"role": "assistant", "content": response})
|
96 |
+
|
97 |
+
# Check if the maximum number of interactions has been reached
|
98 |
+
interaction_count += 1
|
99 |
+
print(f"Interaction count: {interaction_count}") # Print the interaction count
|
100 |
+
if interaction_count >= MAX_INTERACTIONS:
|
101 |
+
farewell_message = "Thank you for the conversation! Have a great day!"
|
102 |
+
history.append({"role": "assistant", "content": farewell_message})
|
103 |
|
104 |
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
105 |
return "", formatted_history, history, interaction_count
|