Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,11 +74,12 @@ interaction_count = 0
|
|
| 74 |
def interact(user_input, history):
|
| 75 |
global tokenizer, model, interaction_count
|
| 76 |
try:
|
| 77 |
-
if tokenizer is None or model is None:
|
| 78 |
raise ValueError("Tokenizer or model is not initialized.")
|
| 79 |
|
| 80 |
# Increment interaction count
|
| 81 |
interaction_count += 1
|
|
|
|
| 82 |
|
| 83 |
# Check if the maximum number of interactions has been reached
|
| 84 |
if interaction_count > MAX_INTERACTIONS:
|
|
@@ -123,8 +124,10 @@ def send_selected_story(title, model_name, system_prompt):
|
|
| 123 |
interaction_count = 0 # Reset interaction count
|
| 124 |
tokenizer, model = load_model(model_name)
|
| 125 |
selected_story = title
|
|
|
|
| 126 |
for story in stories:
|
| 127 |
if story["title"] == title:
|
|
|
|
| 128 |
system_prompt = f"""
|
| 129 |
{system_prompt}
|
| 130 |
Here is the story:
|
|
@@ -141,7 +144,7 @@ Here is the story:
|
|
| 141 |
question_prompt = "Please ask a simple question about the story to encourage interaction."
|
| 142 |
_, formatted_history, chat_history = interact(question_prompt, chat_history)
|
| 143 |
|
| 144 |
-
return formatted_history, chat_history, gr.update(value=[]), gr.update(value=
|
| 145 |
else:
|
| 146 |
print("Combined message is empty.")
|
| 147 |
else:
|
|
|
|
| 74 |
def interact(user_input, history):
|
| 75 |
global tokenizer, model, interaction_count
|
| 76 |
try:
|
| 77 |
+
if tokenizer is None or model is not None:
|
| 78 |
raise ValueError("Tokenizer or model is not initialized.")
|
| 79 |
|
| 80 |
# Increment interaction count
|
| 81 |
interaction_count += 1
|
| 82 |
+
print(f"Interaction count: {interaction_count}") # Print the interaction count
|
| 83 |
|
| 84 |
# Check if the maximum number of interactions has been reached
|
| 85 |
if interaction_count > MAX_INTERACTIONS:
|
|
|
|
| 124 |
interaction_count = 0 # Reset interaction count
|
| 125 |
tokenizer, model = load_model(model_name)
|
| 126 |
selected_story = title
|
| 127 |
+
story_text = ""
|
| 128 |
for story in stories:
|
| 129 |
if story["title"] == title:
|
| 130 |
+
story_text = story["story"]
|
| 131 |
system_prompt = f"""
|
| 132 |
{system_prompt}
|
| 133 |
Here is the story:
|
|
|
|
| 144 |
question_prompt = "Please ask a simple question about the story to encourage interaction."
|
| 145 |
_, formatted_history, chat_history = interact(question_prompt, chat_history)
|
| 146 |
|
| 147 |
+
return formatted_history, chat_history, gr.update(value=[]), gr.update(value=story_text) # Reset the data table and update the selected story textbox
|
| 148 |
else:
|
| 149 |
print("Combined message is empty.")
|
| 150 |
else:
|