Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -500,17 +500,24 @@ def create_new_blank_record(container):
|
|
| 500 |
|
| 501 |
# Function to preprocess the pasted content
|
| 502 |
def preprocess_text(text):
|
| 503 |
-
# Replace CRLF with
|
| 504 |
text = text.replace('\r\n', '\\n')
|
| 505 |
text = text.replace('\r', '\\n')
|
| 506 |
text = text.replace('\n', '\\n')
|
| 507 |
-
|
| 508 |
-
#
|
| 509 |
-
|
| 510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
return text
|
| 512 |
|
| 513 |
-
|
| 514 |
|
| 515 |
# 🎭 Main function - "All the world's a stage, and all the code merely players" -Shakespeare, probably
|
| 516 |
def main():
|
|
|
|
| 500 |
|
| 501 |
# Function to preprocess the pasted content
|
| 502 |
def preprocess_text(text):
|
| 503 |
+
# Replace CRLF and other newline variations with the JSON newline escape sequence
|
| 504 |
text = text.replace('\r\n', '\\n')
|
| 505 |
text = text.replace('\r', '\\n')
|
| 506 |
text = text.replace('\n', '\\n')
|
| 507 |
+
|
| 508 |
+
# Escape double quotes inside the text
|
| 509 |
+
text = text.replace('"', '\\"')
|
| 510 |
+
|
| 511 |
+
# Optionally remove or handle other special characters that might not be JSON-safe
|
| 512 |
+
# Here, we remove characters like tabs or non-ASCII characters (as an example)
|
| 513 |
+
text = re.sub(r'[\t]', ' ', text) # Replace tabs with spaces
|
| 514 |
+
text = re.sub(r'[^\x00-\x7F]+', '', text) # Remove non-ASCII characters
|
| 515 |
+
|
| 516 |
+
# Normalize spaces (strip leading/trailing whitespace)
|
| 517 |
+
text = text.strip()
|
| 518 |
return text
|
| 519 |
|
| 520 |
+
|
| 521 |
|
| 522 |
# 🎭 Main function - "All the world's a stage, and all the code merely players" -Shakespeare, probably
|
| 523 |
def main():
|