Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_fastai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from fastai.text.all import *
|
| 4 |
+
|
| 5 |
+
repo_id = "TU_USUARIO/TU_MODELO_TEXTUAL" # cambia esto si es un modelo de texto
|
| 6 |
+
|
| 7 |
+
learner = from_pretrained_fastai(repo_id)
|
| 8 |
+
labels = learner.dls.vocab
|
| 9 |
+
|
| 10 |
+
def translate_label(label):
|
| 11 |
+
dict = {
|
| 12 |
+
0: "Entailment",
|
| 13 |
+
1: "Neutral",
|
| 14 |
+
2: "Contradiction"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
return dict[label]
|
| 18 |
+
|
| 19 |
+
def predict(text1, text2):
|
| 20 |
+
# Puedes adaptar esto seg煤n c贸mo entrenaste el modelo
|
| 21 |
+
combined_text = text1 + " [SEP] " + text2 # ejemplo: unir textos para tareas de comparaci贸n
|
| 22 |
+
pred, pred_idx, probs = learner.predict(combined_text)
|
| 23 |
+
return {translate_label(labels[i]): float(probs[i]) for i in range(len(labels))}
|
| 24 |
+
|
| 25 |
+
gr.Interface(
|
| 26 |
+
fn=predict,
|
| 27 |
+
inputs=[gr.Textbox(label="Texto 1"), gr.Textbox(label="Texto 2")],
|
| 28 |
+
outputs=gr.Label(num_top_classes=3),
|
| 29 |
+
).launch(share=False)
|