Update app.py (#1)
Browse files- Update app.py (56721381d060b57bbaa52cc503c2a7ee483aef3a)
Co-authored-by: Jose Carlos Vílchez Villegas <JCarlos@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import utils
|
|
|
|
| 3 |
|
| 4 |
from transformers import pipeline
|
| 5 |
from transformers import AutoTokenizer
|
|
@@ -11,20 +13,64 @@ model_berto='hackathon-somos-nlp-2023/DiagTrast-Berto'
|
|
| 11 |
tokenizer_berto = AutoTokenizer.from_pretrained(model_berto)
|
| 12 |
classifier_berto = pipeline("text-classification", model=model_berto)
|
| 13 |
|
| 14 |
-
model_xml='hackathon-somos-nlp-2023/DiagTrast-
|
| 15 |
tokenizer_xml = AutoTokenizer.from_pretrained(model_xml)
|
| 16 |
classifier_xml = pipeline("text-classification", model=model_xml)
|
| 17 |
|
| 18 |
#####################
|
| 19 |
|
| 20 |
-
st.title('Diagnóstico de Trastornos Mentales')
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
value = 'La gente cuando me ve por la calle me mira y halagan mi belleza')
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
st.markdown(
|
| 29 |
-
st.
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
import utils
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
from transformers import pipeline
|
| 7 |
from transformers import AutoTokenizer
|
|
|
|
| 13 |
tokenizer_berto = AutoTokenizer.from_pretrained(model_berto)
|
| 14 |
classifier_berto = pipeline("text-classification", model=model_berto)
|
| 15 |
|
| 16 |
+
model_xml='hackathon-somos-nlp-2023/DiagTrast-xlm-roberta-base'
|
| 17 |
tokenizer_xml = AutoTokenizer.from_pretrained(model_xml)
|
| 18 |
classifier_xml = pipeline("text-classification", model=model_xml)
|
| 19 |
|
| 20 |
#####################
|
| 21 |
|
| 22 |
+
st.title('🏥 Diagnóstico de Trastornos Mentales')
|
| 23 |
|
| 24 |
+
DemoTab, AboutTab = st.tabs(["Demo", "Acerca de"])
|
| 25 |
+
|
| 26 |
+
with AboutTab:
|
| 27 |
+
st.subheader("Motivación")
|
| 28 |
+
st.markdown(
|
| 29 |
+
"[Colocar aquí la motivación]."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
st.subheader("Recursos")
|
| 33 |
+
st.markdown("""
|
| 34 |
+
Modelos usados:
|
| 35 |
+
- [hackathon-somos-nlp-2023/DiagTrast-Berto](https://huggingface.co/hackathon-somos-nlp-2023/DiagTrast-Berto)
|
| 36 |
+
- [hackathon-somos-nlp-2023/DiagTrast-xlm-roberta-base](https://huggingface.co/hackathon-somos-nlp-2023/DiagTrast-xlm-roberta-base)
|
| 37 |
+
|
| 38 |
+
Dataset:
|
| 39 |
+
- [hackathon-somos-nlp-2023/DiagTrast](https://huggingface.co/datasets/hackathon-somos-nlp-2023/DiagTrast)
|
| 40 |
+
""")
|
| 41 |
+
|
| 42 |
+
st.subheader("Equipo")
|
| 43 |
+
st.markdown("""
|
| 44 |
+
- [Alberto Martín Garrido](https://huggingface.co/Stremie)
|
| 45 |
+
- [Edgar Mencia]()
|
| 46 |
+
- [Miguel Ángel Solís Orozco](https://huggingface.co/homosapienssapiens)
|
| 47 |
+
- [Jose Carlos Vílchez Villegas](https://huggingface.co/JCarlos)
|
| 48 |
+
""")
|
| 49 |
+
|
| 50 |
+
with DemoTab:
|
| 51 |
+
with st.form(key="diagtrast_form"):
|
| 52 |
+
sintomas = st.text_input(label = 'Introduce síntomas:',
|
| 53 |
value = 'La gente cuando me ve por la calle me mira y halagan mi belleza')
|
| 54 |
|
| 55 |
+
submit_button = st.form_submit_button(label="Clasificar")
|
| 56 |
+
|
| 57 |
+
if submit_button and not sintomas:
|
| 58 |
+
st.warning("⚠️ Debe introducir los síntomas.")
|
| 59 |
+
|
| 60 |
+
elif submit_button:
|
| 61 |
+
with st.spinner('Clasificando...'):
|
| 62 |
+
pred_berto = classifier_berto.predict(utils.clean_text(sintomas))
|
| 63 |
+
pred_xml = classifier_xml.predict(utils.clean_text(sintomas))
|
| 64 |
+
|
| 65 |
+
df = pd.DataFrame({
|
| 66 |
+
'Modelo': ["DiagTrast-Berto", "DiagTrast-xlm-roberta-base"],
|
| 67 |
+
'Diagnóstico': [pred_berto[0]['label'], pred_xml[0]['label']],
|
| 68 |
+
'Score': [f"{pred_berto[0]['score']:.2%}", f"{pred_xml[0]['score']:.2%}"]
|
| 69 |
+
})
|
| 70 |
|
| 71 |
+
st.markdown("### Resultados:")
|
| 72 |
+
st.caption("")
|
| 73 |
|
| 74 |
+
st.dataframe(df, use_container_width=True)
|
| 75 |
+
st.caption("")
|
| 76 |
+
alert = st.success("✅ ¡Hecho!")
|