Spaces:
Running
Running
import streamlit as st | |
from transformers import pipeline | |
#Nombre_modelo = 'pysentimiento/robertuito-sentiment-analysis' | |
st.title("Ejercicio interfaz transformers pipeline") | |
model_options = [ | |
"facebook/bart-large-mnli", | |
"roberta-large-mnli", | |
"cross-encoder/nli-roberta-base" | |
] | |
# Seleccionar el modelo del pipeline | |
selected_model = st.selectbox("Selecciona un modelo", model_options) | |
#funcion eleccion del modelo | |
def load_pipeline(model_name): | |
return pipeline("zero-shot-classification", model=model_name, device=0) | |
#asignacion del modelo a usar | |
classifier = load_pipeline(selected_model) | |
# Entrada de texto para la oraci贸n | |
nombre = st.text_input("Ingrese un nombre a clasificar:") | |
etiquetas = st.text_area( | |
"Ingresa las categor铆as separadas por comas:", | |
placeholder="Ejemplo: biology, movies, technology" | |
) | |
# Bot贸n para clasificar | |
if st.button("Clasificar"): | |
# Show a spinner during a process | |
with st.spinner(text="In progress"): | |
time.sleep(3) | |
st.success("Done") | |
if nombre and etiquetas: | |
# Procesar las categor铆as ingresadas por el usuario | |
labels = [label.strip() for label in etiquetas.split(",")] | |
# Obtener las predicciones | |
result = classifier(nombre, candidate_labels=labels) | |
# Mostrar los resultados | |
st.subheader("Resultados de Clasificaci贸n") | |
#for label, score in zip(result["labels"], result["scores"]): | |
# st.write(f"**{label}**: {score:.2f}") | |
for label, score in zip(result["labels"], result["scores"]): | |
with st.container(): | |
st.markdown( | |
f""" | |
<div style="background-color:#f9f9f9;padding:10px;margin-bottom:10px;border-radius:5px;border: 1px solid #ddd;"> | |
<h4 style="margin:0;">{label}</h4> | |
<p style="margin:0;">Confianza: <b>{score:.2f}</b></p> | |
</div> | |
""", | |
unsafe_allow_html=True, | |
) | |
else: | |
st.warning("Por favor, ingresa una oraci贸n y categor铆as v谩lidas.") | |
#Clasificador = pipeline('sentiment-analysis', model = Nombre_modelo,device='cuda') | |
#Res=Cla("sundays are good day for relaxing") | |
#print(Res) | |