Update app.py
Browse files
app.py
CHANGED
@@ -8,17 +8,27 @@ hf_token = os.environ.get('HF_TOKEN', None)
|
|
8 |
tokenizer = AutoTokenizer.from_pretrained("hajili/mt5-spell-correction-azerbaijani", token=hf_token)
|
9 |
model = AutoModelForSeq2SeqLM.from_pretrained("hajili/mt5-spell-correction-azerbaijani", token=hf_token)
|
10 |
|
|
|
|
|
|
|
11 |
def correct(sentence):
|
12 |
sentence = sentence.lower().translate(str.maketrans('','', string.punctuation)).strip()
|
|
|
13 |
batch = tokenizer(sentence, return_tensors="pt")
|
14 |
generated_ids = model.generate(batch["input_ids"])
|
15 |
output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
input_component = gr.Textbox(label = "Giriş cümləsini yazın")
|
19 |
output_component = gr.Textbox(label = "Modelin cavabına əsasən verilən cümlənin düzgün yazılışı:")
|
|
|
20 |
examples = [["inweallah duzeler qardawim ureyini cox sixma her wey yaxwi olacax"], ["veziyet hec de urek acan deyil hami xeberi gozleyir ki gorek ne olacaq imkanin olsa sen de zeng eleyib bri xeber sorusharsan xahis edirem anan qurban gozderine"]]
|
21 |
-
description = "- Bu model Azərbaycan dilində yazı səhvlərini düzəltmək üçün dizayn edilib.\n- Modeli test etmək üçün giriş cümləsini daxil edin
|
22 |
-
demo = gr.Interface(correct, inputs = input_component, outputs=output_component, examples=examples, title = "Azərbaycan dilində yazı səhvlərinin düzəlişi üçün dil modeli", description=description)
|
23 |
|
24 |
demo.launch()
|
|
|
8 |
tokenizer = AutoTokenizer.from_pretrained("hajili/mt5-spell-correction-azerbaijani", token=hf_token)
|
9 |
model = AutoModelForSeq2SeqLM.from_pretrained("hajili/mt5-spell-correction-azerbaijani", token=hf_token)
|
10 |
|
11 |
+
tokenizer_new = AutoTokenizer.from_pretrained("hajili/spell-correction-azerbaijani-v2", token=hf_token)
|
12 |
+
model_new = AutoModelForSeq2SeqLM.from_pretrained("hajili/spell-correction-azerbaijani-v2", token=hf_token)
|
13 |
+
|
14 |
def correct(sentence):
|
15 |
sentence = sentence.lower().translate(str.maketrans('','', string.punctuation)).strip()
|
16 |
+
|
17 |
batch = tokenizer(sentence, return_tensors="pt")
|
18 |
generated_ids = model.generate(batch["input_ids"])
|
19 |
output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
20 |
+
|
21 |
+
batch_new = tokenizer_new(sentence, return_tensors="pt")
|
22 |
+
generated_ids_new = model_new.generate(batch_new["input_ids"])
|
23 |
+
output_new = tokenizer_new.batch_decode(generated_ids_new, skip_special_tokens=True)
|
24 |
+
|
25 |
+
return output[0], output_new[0]
|
26 |
|
27 |
input_component = gr.Textbox(label = "Giriş cümləsini yazın")
|
28 |
output_component = gr.Textbox(label = "Modelin cavabına əsasən verilən cümlənin düzgün yazılışı:")
|
29 |
+
output_component_new = gr.Textbox(label = "Yeni modelin cavabına əsasən verilən cümlənin düzgün yazılışı:")
|
30 |
examples = [["inweallah duzeler qardawim ureyini cox sixma her wey yaxwi olacax"], ["veziyet hec de urek acan deyil hami xeberi gozleyir ki gorek ne olacaq imkanin olsa sen de zeng eleyib bri xeber sorusharsan xahis edirem anan qurban gozderine"]]
|
31 |
+
description = "- Bu model Azərbaycan dilində yazı səhvlərini düzəltmək üçün dizayn edilib.\n- Modeli test etmək üçün giriş cümləsini daxil edin."
|
32 |
+
demo = gr.Interface(correct, inputs = input_component, outputs=[output_component, output_component_new], examples=examples, title = "Azərbaycan dilində yazı səhvlərinin düzəlişi üçün dil modeli", description=description)
|
33 |
|
34 |
demo.launch()
|