Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,48 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
-
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Load your custom model and tokenizer
|
| 6 |
model_name = "MiVaCod/mbart-neutralization"
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
title="Sentence Correction",
|
| 23 |
-
description="Enter a sentence to be corrected:",
|
| 24 |
-
theme="compact"
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
# Launch the interface
|
| 28 |
-
gr.Interface(fn=predict, inputs=gr.inputs.Textbox, outputs=gr.outputs.Textbox).launch(share=False)
|
|
|
|
| 1 |
+
# import torch
|
| 2 |
+
# from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
# import gradio as gr
|
| 4 |
+
|
| 5 |
+
# # Load your custom model and tokenizer
|
| 6 |
+
# model_name = "MiVaCod/mbart-neutralization"
|
| 7 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
# model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# # Function to correct sentences
|
| 11 |
+
# def predict(sentence):
|
| 12 |
+
# inputs = tokenizer.encode("correction: " + sentence, return_tensors="pt", max_length=512, truncation=True)
|
| 13 |
+
# outputs = model.generate(inputs, max_length=128, num_beams=4, early_stopping=True)
|
| 14 |
+
# corrected_sentence = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
# return corrected_sentence
|
| 16 |
+
|
| 17 |
+
# # Gradio Interface
|
| 18 |
+
# iface = gr.Interface(
|
| 19 |
+
# fn=correct_sentence,
|
| 20 |
+
# inputs="text",
|
| 21 |
+
# outputs="text",
|
| 22 |
+
# title="Sentence Correction",
|
| 23 |
+
# description="Enter a sentence to be corrected:",
|
| 24 |
+
# theme="compact"
|
| 25 |
+
# )
|
| 26 |
+
|
| 27 |
+
# # Launch the interface
|
| 28 |
+
# gr.Interface(fn=predict, inputs=gr.inputs.Textbox, outputs=gr.outputs.Textbox).launch(share=False)
|
| 29 |
+
|
| 30 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 31 |
+
import gradio as grad
|
| 32 |
|
|
|
|
| 33 |
model_name = "MiVaCod/mbart-neutralization"
|
| 34 |
+
text2text_tkn= T5Tokenizer.from_pretrained(model_name)
|
| 35 |
+
mdl = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 36 |
+
|
| 37 |
+
def text2text_paraphrase(sentence1,sentence2):
|
| 38 |
+
inp1 = "rte sentence1: "+sentence1
|
| 39 |
+
inp2 = "sentence2: "+sentence2
|
| 40 |
+
combined_inp=inp1+" "+inp2
|
| 41 |
+
enc = text2text_tkn(combined_inp, return_tensors="pt")
|
| 42 |
+
tokens = mdl.generate(**enc)
|
| 43 |
+
response=text2text_tkn.batch_decode(tokens)
|
| 44 |
+
return response
|
| 45 |
+
|
| 46 |
+
sent1=grad.Textbox(lines=1, label="Frase misógina", placeholder="Introduce una frase misógina")
|
| 47 |
+
out=grad.Textbox(lines=1, label="Frase corregida")
|
| 48 |
+
grad.Interface(text2text_paraphrase, inputs=[sent1,sent2], outputs=out).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|