import gradio as gr from transformers import pipeline # Cargar el modelo model = pipeline('text-classification', model='desarrolloasesoreslocales/SetFit', tokenizer='desarrolloasesoreslocales/SetFit') # Mapear las etiquetas id2label = {0: "World", 1: "Sports", 2: "Business", 3: "Sci/Tech"} # Definir la función de predicción def predict(text): result = model(text)[0] label = id2label[result['label']] score = result['score'] return f'Clase: {label}, Puntuación: {score:.4f}' # Crear una interfaz Gradio iface = gr.Interface( fn=predict, inputs=gr.inputs.Textboxboxboxboxboxbox(), outputs=gr.outputs.Textboxboxboxboxboxbox(), live=True, layout='vertical', title="Clasificador de Texto" ) # Iniciar la interfaz Gradio iface.launch()