Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,21 +8,16 @@ learn = from_pretrained_fastai("ivferns/clasificador_textos")
|
|
| 8 |
# Función de predicción
|
| 9 |
def clasificar_texto(texto):
|
| 10 |
pred, idx, probs = learn.predict(texto)
|
| 11 |
-
|
| 12 |
-
top_vals, top_idxs = probs.topk(3)
|
| 13 |
-
top_vals = top_vals.tolist()
|
| 14 |
-
top_idxs = top_idxs.tolist()
|
| 15 |
-
# Construir un diccionario {clase: probabilidad}
|
| 16 |
-
return { CLASSES[i]: float(top_vals[j])
|
| 17 |
-
for j, i in enumerate(top_idxs) }
|
| 18 |
|
| 19 |
# Interfaz Gradio
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=clasificar_texto,
|
| 22 |
inputs=gr.Textbox(lines=5, label="Introduce el texto"),
|
| 23 |
-
outputs=gr.Label(
|
| 24 |
title="Clasificador de textos",
|
| 25 |
description="Modelo de clasificación de textos fine-tuned con FastAI y desplegado en Hugging Face Spaces."
|
| 26 |
)
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
| 8 |
# Función de predicción
|
| 9 |
def clasificar_texto(texto):
|
| 10 |
pred, idx, probs = learn.predict(texto)
|
| 11 |
+
return str(pred)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Interfaz Gradio
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=clasificar_texto,
|
| 16 |
inputs=gr.Textbox(lines=5, label="Introduce el texto"),
|
| 17 |
+
outputs=gr.Label(label="Prediccion"),
|
| 18 |
title="Clasificador de textos",
|
| 19 |
description="Modelo de clasificación de textos fine-tuned con FastAI y desplegado en Hugging Face Spaces."
|
| 20 |
)
|
| 21 |
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|