Spaces:
Runtime error
Runtime error
desarrolloasesoreslocales
commited on
Commit
·
9e7ab7c
1
Parent(s):
eae6750
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Cargar el modelo
|
5 |
+
model = pipeline('text-classification', model='desarrolloasesoreslocales/SetFit', tokenizer='desarrolloasesoreslocales/SetFit')
|
6 |
+
|
7 |
+
# Mapear las etiquetas
|
8 |
+
id2label = {0: "World", 1: "Sports", 2: "Business", 3: "Sci/Tech"}
|
9 |
+
|
10 |
+
# Definir la función de predicción
|
11 |
+
def predict(text):
|
12 |
+
result = model(text)[0]
|
13 |
+
label = id2label[result['label']]
|
14 |
+
score = result['score']
|
15 |
+
return f'Clase: {label}, Puntuación: {score:.4f}'
|
16 |
+
|
17 |
+
# Crear una interfaz Gradio
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=predict,
|
20 |
+
inputs=gr.inputs.Textboxboxboxboxboxbox(),
|
21 |
+
outputs=gr.outputs.Textboxboxboxboxboxbox(),
|
22 |
+
live=True,
|
23 |
+
layout='vertical',
|
24 |
+
title="Clasificador de Texto"
|
25 |
+
)
|
26 |
+
|
27 |
+
# Iniciar la interfaz Gradio
|
28 |
+
iface.launch()
|