First try testing model
Browse files- __init__.py +0 -0
- __pycache__/utils.cpython-38.pyc +0 -0
- app.py +20 -4
- utils.py +43 -0
__init__.py
ADDED
|
File without changes
|
__pycache__/utils.cpython-38.pyc
ADDED
|
Binary file (1.55 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,8 +1,24 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
st.write(x, 'squared is', x * x)
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import utils
|
| 3 |
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from transformers import AutoTokenizer
|
| 6 |
+
from transformers import AutoModelForSequenceClassification
|
| 7 |
|
| 8 |
+
#####################
|
|
|
|
| 9 |
|
| 10 |
+
model_id='hackathon-somos-nlp-2023/DiagTrast'
|
| 11 |
+
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 13 |
+
|
| 14 |
+
classifier = pipeline("text-classification",
|
| 15 |
+
model=model_id)
|
| 16 |
+
|
| 17 |
+
#####################
|
| 18 |
+
|
| 19 |
+
st.title('Diagnóstico de Trastornos Mentales')
|
| 20 |
+
|
| 21 |
+
sintomas = st.text_input(label = 'Introduce síntomas',
|
| 22 |
+
value = '')
|
| 23 |
+
|
| 24 |
+
st.markdown(classifier(utils.clean_text(sintomas)))
|
utils.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import nltk
|
| 3 |
+
from nltk.corpus import stopwords
|
| 4 |
+
|
| 5 |
+
def eliminar_acento(s):
|
| 6 |
+
replacements = (
|
| 7 |
+
("á", "a"),
|
| 8 |
+
("é", "e"),
|
| 9 |
+
("í", "i"),
|
| 10 |
+
("ó", "o"),
|
| 11 |
+
("ú", "u"),
|
| 12 |
+
)
|
| 13 |
+
for a, b in replacements:
|
| 14 |
+
s = s.replace(a, b).replace(a.upper(), b.upper())
|
| 15 |
+
return s
|
| 16 |
+
|
| 17 |
+
def eliminar_patrones_stopwords(text):
|
| 18 |
+
nltk.download('stopwords')
|
| 19 |
+
lstopwords = set(stopwords.words('spanish'))
|
| 20 |
+
|
| 21 |
+
text = [word for word in text.strip().split() if not word in lstopwords]
|
| 22 |
+
text = ' '.join(text)
|
| 23 |
+
return text
|
| 24 |
+
|
| 25 |
+
def eliminar_espacios_blancos(texto):
|
| 26 |
+
texto = re.sub(r"\:|\_", '', texto)
|
| 27 |
+
texto = re.sub(r"o\/a", 'o', texto)
|
| 28 |
+
|
| 29 |
+
texto = re.sub(r'[^\w\s]', '', texto)
|
| 30 |
+
return texto
|
| 31 |
+
|
| 32 |
+
def clean_text(original):
|
| 33 |
+
original = re.sub(r'\w+(?:\.+\w+)*', lambda x: x.group(0).replace('.', ' '), original)
|
| 34 |
+
original = re.sub(r'\.','' , original)
|
| 35 |
+
|
| 36 |
+
texto = eliminar_acento(original)
|
| 37 |
+
texto = eliminar_espacios_blancos(texto)
|
| 38 |
+
texto = re.sub(r" +", ' ', texto)
|
| 39 |
+
|
| 40 |
+
texto = texto.lower()
|
| 41 |
+
texto = eliminar_patrones_stopwords(texto)
|
| 42 |
+
original = re.sub(r" +", ' ', texto)
|
| 43 |
+
return texto
|