Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,20 @@ import requests
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import re
|
|
|
|
| 6 |
from urllib.parse import unquote
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def filter_non_alphanumeric(text):
|
| 8 |
# Use regular expressions to filter out non-alphanumeric characters
|
| 9 |
-
alphanumeric_text =
|
| 10 |
return alphanumeric_text
|
| 11 |
|
| 12 |
def send_to_corrade(filtered_response):
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
+
import emoji
|
| 7 |
from urllib.parse import unquote
|
| 8 |
+
def filter_text_and_preserve_emojis(text):
|
| 9 |
+
# Function to identify if a character is an emoji
|
| 10 |
+
def is_emoji(s):
|
| 11 |
+
return s in emoji.UNICODE_EMOJI_ENGLISH
|
| 12 |
+
|
| 13 |
+
# Replace characters not matching our allowed set or emojis with an empty string
|
| 14 |
+
filtered_text = ''.join(c if re.match(r'[a-zA-Z0-9\s.,?!\'"]', c) or is_emoji(c) else '' for c in text)
|
| 15 |
+
|
| 16 |
+
return filtered_text
|
| 17 |
def filter_non_alphanumeric(text):
|
| 18 |
# Use regular expressions to filter out non-alphanumeric characters
|
| 19 |
+
alphanumeric_text = filter_text_and_preserve_emojis(text)
|
| 20 |
return alphanumeric_text
|
| 21 |
|
| 22 |
def send_to_corrade(filtered_response):
|