import streamlit as st from transformers import pipeline # ============================== # CONFIGURACIÓN DE LA APLICACIÓN # ============================== st.set_page_config(page_title="Detección de Toxicidad", page_icon="🤖", layout="centered") st.title("🧠 Detección de Toxicidad en Comentarios") st.markdown("Modelo fine-tuneado en DistilBERT para detectar lenguaje tóxico en texto.") # ============================== # CARGAR MODELO DESDE HF HUB # ============================== @st.cache_resource def load_model(): model_id = "solinsoft/distilbert-finetuned-toxic-comments" clf = pipeline("text-classification", model=model_id) return clf clf = load_model() # ============================== # INTERFAZ DE USUARIO # ============================== texto = st.text_area("Escribe un comentario para analizar:", height=150) if st.button("Analizar"): if texto.strip(): with st.spinner("Analizando el texto..."): result = clf(texto)[0] label = result['label'] score = result['score'] st.success("**Resultado:**",label,score:.2%) else: st.warning("Por favor, escribe un texto antes de analizar.") st.markdown("---") st.caption("Desarrollado con ❤️ usando Hugging Face")