Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +41 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
5 |
+
|
6 |
+
## Model
|
7 |
+
|
8 |
+
access_token = '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'
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("PhongLT/ViLexNorm-bartpho-syllable-base-10e-nopre", token=access_token)
|
10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("PhongLT/ViLexNorm-bartpho-syllable-base-10e-nopre", token=access_token)
|
11 |
+
|
12 |
+
|
13 |
+
def normalize(source_text):
|
14 |
+
input_ids = tokenizer( source_text,
|
15 |
+
return_tensors="pt",
|
16 |
+
max_length=512,
|
17 |
+
padding="max_length",
|
18 |
+
truncation= True).input_ids
|
19 |
+
|
20 |
+
output_ids = model.generate(input_ids,
|
21 |
+
max_length=512)
|
22 |
+
|
23 |
+
return tokenizer.decode(output_ids[0],
|
24 |
+
skip_special_tokens=True,
|
25 |
+
max_length=512)
|
26 |
+
|
27 |
+
# Create title, description and article strings
|
28 |
+
title = "Lexical Normalization Test"
|
29 |
+
description = ""
|
30 |
+
example_list = ["cl j v tr", "kh hỉu c đg nghĩ j nựa"]
|
31 |
+
|
32 |
+
demo = gr.Interface(fn=normalize,
|
33 |
+
inputs="text",
|
34 |
+
outputs="text",
|
35 |
+
examples=example_list,
|
36 |
+
title=title,
|
37 |
+
description=description)
|
38 |
+
|
39 |
+
# Launch the demo!
|
40 |
+
demo.launch(debug=False, # print errors locally?
|
41 |
+
share=True) # generate a publically shareable URL?
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
sentencepiece
|