fvelasco
commited on
Commit
•
8eb0b06
1
Parent(s):
243307b
modified gradio app
Browse files- app.py +7 -21
- requirements.txt +122 -0
app.py
CHANGED
@@ -1,47 +1,34 @@
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
-
import os
|
3 |
-
os.environ["CUDA_VISIBLE_DEVICES"]="0"
|
4 |
import gradio as gr
|
5 |
|
6 |
-
def greet(name):
|
7 |
-
return "Hello " + name + "!!"
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
import torch
|
|
|
13 |
first_generation = True
|
14 |
prefix = ''
|
15 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
16 |
|
17 |
-
|
18 |
model_checkpoint = "fermaat/es_nlp_text_neutralizer"
|
19 |
|
20 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
# model = T5ForConditionalGeneration.from_pretrained(model_checkpoint)
|
25 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
|
26 |
# TODO: jarl!! check this for avoiding short segments
|
27 |
model.config.max_length = 512
|
28 |
model.to(device)
|
29 |
-
|
30 |
-
|
31 |
# sentences = ["El libro relata las aventuras y desventuras de un hidalgo de 50 años llamado Alonso Quijano, quien decide ser un caballero andante como aquellos que aparecen en sus libros de caballerías favoritos.Las hazañas de don Quijote están contenidas en dos tomos que narran tres salidas. Por un lado, la “Primera parte” denominada como El ingenioso Hidalgo Don Quijote de la Mancha está formada por 52 capítulos y en ella se encuentran la primera salida y la segunda salida."]
|
32 |
# sentences = ['De acuerdo con las informaciones anteriores , las alumnas se han quejado de la actitud de los profesores en los exámenes finales. Los representantes estudiantiles son los alumnos Juanju y Javi.']
|
33 |
-
def get_output(
|
34 |
-
inputs = tokenizer([prefix + sentence
|
35 |
with torch.no_grad():
|
36 |
if first_generation:
|
37 |
-
|
38 |
input_ids=inputs["input_ids"].to(device),
|
39 |
attention_mask=inputs["attention_mask"].to(device),
|
40 |
do_sample=False, # disable sampling to test if batching affects output
|
41 |
)
|
42 |
else:
|
43 |
|
44 |
-
|
45 |
input_ids=inputs["input_ids"].to(device),
|
46 |
attention_mask=inputs["attention_mask"].to(device),
|
47 |
do_sample=False,
|
@@ -50,10 +37,9 @@ def get_output(sentences, first_generation=True):
|
|
50 |
# length_penalty=1.0,
|
51 |
early_stopping=True# disable sampling to test if batching affects output
|
52 |
)
|
53 |
-
|
54 |
-
preds = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in output_sequences]
|
55 |
return preds
|
56 |
-
|
57 |
|
58 |
|
59 |
iface = gr.Interface(fn=get_output, inputs="text", outputs="text")
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import torch
|
5 |
+
|
6 |
first_generation = True
|
7 |
prefix = ''
|
8 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
9 |
|
|
|
10 |
model_checkpoint = "fermaat/es_nlp_text_neutralizer"
|
11 |
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
13 |
|
|
|
|
|
|
|
14 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
|
15 |
# TODO: jarl!! check this for avoiding short segments
|
16 |
model.config.max_length = 512
|
17 |
model.to(device)
|
|
|
|
|
18 |
# sentences = ["El libro relata las aventuras y desventuras de un hidalgo de 50 años llamado Alonso Quijano, quien decide ser un caballero andante como aquellos que aparecen en sus libros de caballerías favoritos.Las hazañas de don Quijote están contenidas en dos tomos que narran tres salidas. Por un lado, la “Primera parte” denominada como El ingenioso Hidalgo Don Quijote de la Mancha está formada por 52 capítulos y en ella se encuentran la primera salida y la segunda salida."]
|
19 |
# sentences = ['De acuerdo con las informaciones anteriores , las alumnas se han quejado de la actitud de los profesores en los exámenes finales. Los representantes estudiantiles son los alumnos Juanju y Javi.']
|
20 |
+
def get_output(sentence, first_generation=True):
|
21 |
+
inputs = tokenizer([prefix + sentence], return_tensors="pt", padding=True)
|
22 |
with torch.no_grad():
|
23 |
if first_generation:
|
24 |
+
output_sequence = model.generate(
|
25 |
input_ids=inputs["input_ids"].to(device),
|
26 |
attention_mask=inputs["attention_mask"].to(device),
|
27 |
do_sample=False, # disable sampling to test if batching affects output
|
28 |
)
|
29 |
else:
|
30 |
|
31 |
+
output_sequence = model.generate(
|
32 |
input_ids=inputs["input_ids"].to(device),
|
33 |
attention_mask=inputs["attention_mask"].to(device),
|
34 |
do_sample=False,
|
|
|
37 |
# length_penalty=1.0,
|
38 |
early_stopping=True# disable sampling to test if batching affects output
|
39 |
)
|
40 |
+
preds = tokenizer.decode(output_sequence[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
|
|
41 |
return preds
|
42 |
+
|
43 |
|
44 |
|
45 |
iface = gr.Interface(fn=get_output, inputs="text", outputs="text")
|
requirements.txt
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiohttp==3.8.1
|
2 |
+
aiosignal==1.2.0
|
3 |
+
analytics-python==1.4.0
|
4 |
+
anyio==3.5.0
|
5 |
+
argon2-cffi==21.3.0
|
6 |
+
argon2-cffi-bindings==21.2.0
|
7 |
+
asgiref==3.5.0
|
8 |
+
async-timeout==4.0.2
|
9 |
+
asynctest==0.13.0
|
10 |
+
attrs==21.4.0
|
11 |
+
backcall==0.2.0
|
12 |
+
backoff==1.10.0
|
13 |
+
bcrypt==3.2.0
|
14 |
+
beautifulsoup4==4.10.0
|
15 |
+
bleach==4.1.0
|
16 |
+
certifi==2021.10.8
|
17 |
+
cffi==1.15.0
|
18 |
+
charset-normalizer==2.0.12
|
19 |
+
click==8.0.4
|
20 |
+
cryptography==36.0.2
|
21 |
+
cycler==0.11.0
|
22 |
+
datasets==2.0.0
|
23 |
+
debugpy==1.6.0
|
24 |
+
decorator==5.1.1
|
25 |
+
defusedxml==0.7.1
|
26 |
+
dill==0.3.4
|
27 |
+
entrypoints==0.4
|
28 |
+
fastapi==0.75.0
|
29 |
+
ffmpy==0.3.0
|
30 |
+
filelock==3.6.0
|
31 |
+
fonttools==4.31.2
|
32 |
+
frozenlist==1.3.0
|
33 |
+
fsspec==2022.2.0
|
34 |
+
gradio==2.8.14
|
35 |
+
h11==0.13.0
|
36 |
+
huggingface-hub==0.4.0
|
37 |
+
idna==3.3
|
38 |
+
importlib-metadata==4.11.3
|
39 |
+
importlib-resources==5.6.0
|
40 |
+
ipykernel==6.9.2
|
41 |
+
ipython==7.32.0
|
42 |
+
ipython-genutils==0.2.0
|
43 |
+
jedi==0.18.1
|
44 |
+
Jinja2==3.1.1
|
45 |
+
joblib==1.1.0
|
46 |
+
jsonschema==4.4.0
|
47 |
+
jupyter-client==7.1.2
|
48 |
+
jupyter-core==4.9.2
|
49 |
+
jupyterlab-pygments==0.1.2
|
50 |
+
kiwisolver==1.4.1
|
51 |
+
linkify-it-py==1.0.3
|
52 |
+
markdown-it-py==2.0.1
|
53 |
+
MarkupSafe==2.1.1
|
54 |
+
matplotlib==3.5.1
|
55 |
+
matplotlib-inline==0.1.3
|
56 |
+
mdit-py-plugins==0.3.0
|
57 |
+
mdurl==0.1.0
|
58 |
+
mistune==0.8.4
|
59 |
+
monotonic==1.6
|
60 |
+
multidict==6.0.2
|
61 |
+
multiprocess==0.70.12.2
|
62 |
+
nbclient==0.5.13
|
63 |
+
nbconvert==6.4.5
|
64 |
+
nbformat==5.2.0
|
65 |
+
nest-asyncio==1.5.4
|
66 |
+
notebook==6.4.10
|
67 |
+
numpy==1.21.5
|
68 |
+
orjson==3.6.7
|
69 |
+
packaging==21.3
|
70 |
+
pandas==1.3.5
|
71 |
+
pandocfilters==1.5.0
|
72 |
+
paramiko==2.10.3
|
73 |
+
parso==0.8.3
|
74 |
+
pexpect==4.8.0
|
75 |
+
pickleshare==0.7.5
|
76 |
+
Pillow==9.0.1
|
77 |
+
prometheus-client==0.13.1
|
78 |
+
prompt-toolkit==3.0.28
|
79 |
+
psutil==5.9.0
|
80 |
+
ptyprocess==0.7.0
|
81 |
+
pyarrow==7.0.0
|
82 |
+
pycparser==2.21
|
83 |
+
pycryptodome==3.14.1
|
84 |
+
pydantic==1.9.0
|
85 |
+
pydub==0.25.1
|
86 |
+
Pygments==2.11.2
|
87 |
+
PyNaCl==1.5.0
|
88 |
+
pyparsing==3.0.7
|
89 |
+
pyrsistent==0.18.1
|
90 |
+
python-dateutil==2.8.2
|
91 |
+
python-multipart==0.0.5
|
92 |
+
pytz==2022.1
|
93 |
+
PyYAML==6.0
|
94 |
+
pyzmq==22.3.0
|
95 |
+
regex==2022.3.15
|
96 |
+
requests==2.27.1
|
97 |
+
responses==0.18.0
|
98 |
+
sacremoses==0.0.49
|
99 |
+
Send2Trash==1.8.0
|
100 |
+
six==1.16.0
|
101 |
+
sniffio==1.2.0
|
102 |
+
soupsieve==2.3.1
|
103 |
+
starlette==0.17.1
|
104 |
+
terminado==0.13.3
|
105 |
+
testpath==0.6.0
|
106 |
+
tokenizers==0.11.6
|
107 |
+
torch==1.10.2+cu113
|
108 |
+
torchaudio==0.10.2+cu113
|
109 |
+
torchvision==0.11.3+cu113
|
110 |
+
tornado==6.1
|
111 |
+
tqdm==4.63.1
|
112 |
+
traitlets==5.1.1
|
113 |
+
transformers==4.17.0
|
114 |
+
typing_extensions==4.1.1
|
115 |
+
uc-micro-py==1.0.1
|
116 |
+
urllib3==1.26.9
|
117 |
+
uvicorn==0.17.6
|
118 |
+
wcwidth==0.2.5
|
119 |
+
webencodings==0.5.1
|
120 |
+
xxhash==3.0.0
|
121 |
+
yarl==1.7.2
|
122 |
+
zipp==3.7.0
|