Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,6 +68,7 @@ tokenizer, model = load_model(selected_model)
|
|
| 68 |
|
| 69 |
# Chat history and interaction counter
|
| 70 |
chat_history = []
|
|
|
|
| 71 |
|
| 72 |
# Function to handle interaction with model
|
| 73 |
@spaces.GPU
|
|
@@ -77,6 +78,12 @@ def interact(user_input, history, interaction_count):
|
|
| 77 |
if tokenizer is None or model is None:
|
| 78 |
raise ValueError("Tokenizer or model is not initialized.")
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
messages = history + [{"role": "user", "content": user_input}]
|
| 81 |
|
| 82 |
# Ensure roles alternate correctly
|
|
@@ -95,13 +102,6 @@ def interact(user_input, history, interaction_count):
|
|
| 95 |
history.append({"role": "user", "content": user_input})
|
| 96 |
history.append({"role": "assistant", "content": response})
|
| 97 |
|
| 98 |
-
interaction_count += 1
|
| 99 |
-
print(f"Interaction count: {interaction_count}")
|
| 100 |
-
|
| 101 |
-
if interaction_count >= MAX_INTERACTIONS:
|
| 102 |
-
response += ". Thank you for the questions. That's all for now. Goodbye!"
|
| 103 |
-
history[-1]["content"] = response
|
| 104 |
-
|
| 105 |
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
| 106 |
return "", formatted_history, history, interaction_count
|
| 107 |
except Exception as e:
|
|
|
|
| 68 |
|
| 69 |
# Chat history and interaction counter
|
| 70 |
chat_history = []
|
| 71 |
+
interaction_count = 0
|
| 72 |
|
| 73 |
# Function to handle interaction with model
|
| 74 |
@spaces.GPU
|
|
|
|
| 78 |
if tokenizer is None or model is None:
|
| 79 |
raise ValueError("Tokenizer or model is not initialized.")
|
| 80 |
|
| 81 |
+
interaction_count += 1
|
| 82 |
+
print(f"Interaction count: {interaction_count}")
|
| 83 |
+
|
| 84 |
+
if interaction_count >= MAX_INTERACTIONS:
|
| 85 |
+
user_input += ". Thank you for the questions. That's all for now. Goodbye!"
|
| 86 |
+
|
| 87 |
messages = history + [{"role": "user", "content": user_input}]
|
| 88 |
|
| 89 |
# Ensure roles alternate correctly
|
|
|
|
| 102 |
history.append({"role": "user", "content": user_input})
|
| 103 |
history.append({"role": "assistant", "content": response})
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
| 106 |
return "", formatted_history, history, interaction_count
|
| 107 |
except Exception as e:
|