Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from nltk.tokenize import word_tokenize
|
|
| 11 |
from collections import Counter
|
| 12 |
import plotly.express as px
|
| 13 |
import emoji
|
|
|
|
| 14 |
|
| 15 |
# Descargar recursos de nltk
|
| 16 |
nltk.download('stopwords')
|
|
@@ -25,6 +26,15 @@ sentiment_analysis = pipeline('sentiment-analysis', model='dccuchile/bert-base-s
|
|
| 25 |
def contiene_emojis(texto):
|
| 26 |
return any(char in emoji.EMOJI_DATA for char in texto)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Funci贸n para procesar el archivo .txt de WhatsApp
|
| 29 |
def cargar_chat_txt(file):
|
| 30 |
content = file.getvalue().decode('utf-8')
|
|
@@ -68,6 +78,7 @@ def cargar_chat_txt(file):
|
|
| 68 |
|
| 69 |
if not df.empty:
|
| 70 |
df['FechaHora'] = pd.to_datetime(df['FechaHora'])
|
|
|
|
| 71 |
return df
|
| 72 |
else:
|
| 73 |
return None
|
|
@@ -88,7 +99,7 @@ def extraer_bigrams_trigrams(mensaje):
|
|
| 88 |
|
| 89 |
# Funciones de urgencia (autor, hora, sentimiento, palabras clave, etc.)
|
| 90 |
def urgencia_por_autor(autor):
|
| 91 |
-
autores_prioritarios = ["Jefe", "Hijo", "Mam谩", "Pap谩", "Esposa"]
|
| 92 |
if any(char in autor for char in ["鉂わ笍", "馃挅", "馃挊", "馃挐", "馃挄"]):
|
| 93 |
return 2
|
| 94 |
return 2 if autor in autores_prioritarios else 0
|
|
@@ -104,7 +115,7 @@ def urgencia_por_sentimiento(sentimiento):
|
|
| 104 |
return etiquetas.get(sentimiento, 0)
|
| 105 |
|
| 106 |
def urgencia_por_palabras_clave(mensaje):
|
| 107 |
-
claves = ["urgente", "es urgente", "es para hoy", "necesito ayuda", "por favor", "con urgencia"]
|
| 108 |
mensaje = mensaje.lower()
|
| 109 |
return 1 if any(clave in mensaje for clave in claves) else 0
|
| 110 |
|
|
|
|
| 11 |
from collections import Counter
|
| 12 |
import plotly.express as px
|
| 13 |
import emoji
|
| 14 |
+
import string
|
| 15 |
|
| 16 |
# Descargar recursos de nltk
|
| 17 |
nltk.download('stopwords')
|
|
|
|
| 26 |
def contiene_emojis(texto):
|
| 27 |
return any(char in emoji.EMOJI_DATA for char in texto)
|
| 28 |
|
| 29 |
+
# Funci贸n para limpiar texto (normalizaci贸n + limpieza de caracteres especiales)
|
| 30 |
+
def limpiar_texto(texto):
|
| 31 |
+
texto = texto.lower()
|
| 32 |
+
texto = re.sub(r'https?://\S+|www\.\S+', '', texto) # eliminar URLs
|
| 33 |
+
texto = re.sub(r'\d+', '', texto) # eliminar n煤meros
|
| 34 |
+
texto = texto.translate(str.maketrans('', '', string.punctuation)) # eliminar puntuaci贸n
|
| 35 |
+
texto = texto.strip()
|
| 36 |
+
return texto
|
| 37 |
+
|
| 38 |
# Funci贸n para procesar el archivo .txt de WhatsApp
|
| 39 |
def cargar_chat_txt(file):
|
| 40 |
content = file.getvalue().decode('utf-8')
|
|
|
|
| 78 |
|
| 79 |
if not df.empty:
|
| 80 |
df['FechaHora'] = pd.to_datetime(df['FechaHora'])
|
| 81 |
+
df['Mensaje'] = df['Mensaje'].apply(limpiar_texto)
|
| 82 |
return df
|
| 83 |
else:
|
| 84 |
return None
|
|
|
|
| 99 |
|
| 100 |
# Funciones de urgencia (autor, hora, sentimiento, palabras clave, etc.)
|
| 101 |
def urgencia_por_autor(autor):
|
| 102 |
+
autores_prioritarios = ["Jefe", "Hijo", "Mam谩", "Pap谩", "Esposa", "Novia"]
|
| 103 |
if any(char in autor for char in ["鉂わ笍", "馃挅", "馃挊", "馃挐", "馃挄"]):
|
| 104 |
return 2
|
| 105 |
return 2 if autor in autores_prioritarios else 0
|
|
|
|
| 115 |
return etiquetas.get(sentimiento, 0)
|
| 116 |
|
| 117 |
def urgencia_por_palabras_clave(mensaje):
|
| 118 |
+
claves = ["urgente", "es urgente", "es para hoy", "necesito ayuda", "por favor", "con urgencia", "rapido", "callo", "caer", "atropellado"]
|
| 119 |
mensaje = mensaje.lower()
|
| 120 |
return 1 if any(clave in mensaje for clave in claves) else 0
|
| 121 |
|