Update app.py
Browse files
app.py
CHANGED
@@ -68,8 +68,6 @@ def generate_response_with_visualization(model, tokenizer, device, messages, gen
|
|
68 |
Returns:
|
69 |
List of visualization states showing the progression and final text
|
70 |
"""
|
71 |
-
# Set random seed for reproducibility
|
72 |
-
torch.manual_seed(42)
|
73 |
|
74 |
# Process constraints
|
75 |
if constraints is None:
|
@@ -212,29 +210,12 @@ def generate_response_with_visualization(model, tokenizer, device, messages, gen
|
|
212 |
response_text = tokenizer.decode(response_tokens, skip_special_tokens=True)
|
213 |
|
214 |
# Clean the response text
|
215 |
-
final_text =
|
|
|
|
|
216 |
|
217 |
return visualization_states, final_text
|
218 |
|
219 |
-
def clean_output_text(text):
|
220 |
-
"""Clean the output text to remove special tokens and fix spacing"""
|
221 |
-
# Remove any remaining [MASK] tokens
|
222 |
-
text = text.replace(MASK_TOKEN, "")
|
223 |
-
|
224 |
-
# Fix common spacing issues with tokenization
|
225 |
-
text = re.sub(r'\s+', ' ', text) # Remove multiple spaces
|
226 |
-
text = re.sub(r' \.', '.', text) # Fix spacing before periods
|
227 |
-
text = re.sub(r' ,', ',', text) # Fix spacing before commas
|
228 |
-
text = re.sub(r' !', '!', text) # Fix spacing before exclamation marks
|
229 |
-
text = re.sub(r' \?', '?', text) # Fix spacing before question marks
|
230 |
-
text = re.sub(r' ;', ';', text) # Fix spacing before semicolons
|
231 |
-
text = re.sub(r' :', ':', text) # Fix spacing before colons
|
232 |
-
|
233 |
-
# Fix beginning and end spacing
|
234 |
-
text = text.strip()
|
235 |
-
|
236 |
-
return text
|
237 |
-
|
238 |
css = '''
|
239 |
.category-legend{display:none}
|
240 |
'''
|
|
|
68 |
Returns:
|
69 |
List of visualization states showing the progression and final text
|
70 |
"""
|
|
|
|
|
71 |
|
72 |
# Process constraints
|
73 |
if constraints is None:
|
|
|
210 |
response_text = tokenizer.decode(response_tokens, skip_special_tokens=True)
|
211 |
|
212 |
# Clean the response text
|
213 |
+
final_text = tokenizer.decode(response_tokens,
|
214 |
+
skip_special_tokens=True,
|
215 |
+
clean_up_tokenization_spaces=True)
|
216 |
|
217 |
return visualization_states, final_text
|
218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
css = '''
|
220 |
.category-legend{display:none}
|
221 |
'''
|