AEUPH commited on
Commit
86c4270
·
verified ·
1 Parent(s): 193c967

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -6,12 +6,11 @@ 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):
 
6
  import emoji
7
  from urllib.parse import unquote
8
  def filter_text_and_preserve_emojis(text):
9
+ # Create a regex pattern that matches allowed characters and emojis
10
+ allowed_pattern = re.compile(r'[a-zA-Z0-9\s.,?!\'"]|' + emoji.get_emoji_regexp().pattern)
 
11
 
12
+ # Use the findall method to keep allowed characters and emojis
13
+ filtered_text = ''.join(allowed_pattern.findall(text))
14
 
15
  return filtered_text
16
  def filter_non_alphanumeric(text):