Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
|
| 4 |
+
# Cargar el modelo y el tokenizador
|
| 5 |
+
model_name = "dagomem/modelo_tweets"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Función de predicción
|
| 10 |
+
def predict_tags(text):
|
| 11 |
+
# Tokenizar el texto de entrada
|
| 12 |
+
encoded_input = tokenizer.encode_plus(
|
| 13 |
+
text,
|
| 14 |
+
padding="longest",
|
| 15 |
+
truncation=True,
|
| 16 |
+
return_tensors="pt"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Realizar la predicción
|
| 20 |
+
output = model(**encoded_input)
|
| 21 |
+
|
| 22 |
+
# Obtener las etiquetas predichas
|
| 23 |
+
predicted_label = output.logits.argmax(dim=1)
|
| 24 |
+
|
| 25 |
+
return predicted_label.item()
|
| 26 |
+
|
| 27 |
+
# Interfaz de usuario
|
| 28 |
+
gr.Interface(
|
| 29 |
+
fn=predict_tags,
|
| 30 |
+
inputs=gr.inputs.Textbox(lines=3, label="Texto"),
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="Etiquetado de Texto",
|
| 33 |
+
description="Ingrese un texto y el modelo preentrenado predecirá la etiqueta asociada.",
|
| 34 |
+
).launch(share=False)
|