File size: 2,087 Bytes
d36d50b
 
 
 
 
ebc546a
d36d50b
 
f81acf7
d36d50b
 
f81acf7
d36d50b
 
 
 
f81acf7
d36d50b
 
 
 
 
 
 
ebc546a
d36d50b
ebc546a
 
d36d50b
 
 
 
ebc546a
 
d36d50b
ebc546a
f81acf7
 
 
ebc546a
d36d50b
 
 
 
 
5314058
 
d36d50b
 
 
 
 
 
5314058
 
d36d50b
 
 
ebc546a
d36d50b
 
ebc546a
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import yaml
import gdown 
import gradio as gr
from predict import PredictTri
from gradio import blocks 

output_path = "tashkeela-d2.pt"
gdrive_templ = "https://drive.google.com/file/d/{}/view?usp=sharing"
if not os.path.exists(output_path):
    model_gdrive_id = "1FGelqImFkESbTyRsx_elkKIOZ9VbhRuo"
    gdown.download(gdrive_templ.format(model_gdrive_id), output=output_path, quiet=False)

output_path = "vocab.vec"
if not os.path.exists(output_path):
    vocab_gdrive_id = "1-0muGvcSYEf8RAVRcwXay4MRex6kmCii"
    gdown.download(gdrive_templ.format(vocab_gdrive_id), output=output_path, quiet=False)

with open("config.yaml", 'r', encoding="utf-8") as file:
    config = yaml.load(file, Loader=yaml.FullLoader)

config["train"]["max-sent-len"] = config["predictor"]["window"]
config["train"]["max-token-count"] = config["predictor"]["window"] * 3

def diacritze(text, do_partial):
    predictor = PredictTri(config, text)
    diacritized_lines = predictor.predict_partial(do_partial=do_partial)
    return diacritized_lines

with gr.Blocks() as demo:
    gr.Markdown(
    """
    # Partial Diacritization: A Context-Contrastive Inference Approach
    ## Authors: Muhammad ElNokrashy, Badr AlKhamissi
    """)

    with gr.Row():
        check_box = gr.Checkbox(label="Partial", info="Apply Partial Diacritics or Full Diacritics")
        threshold_txt = gr.Textbox("")

    input_txt = gr.Textbox(
        placeholder="اكتب هنا", 
        lines=5, 
        label="Input",
        type='text',
        rtl=True,
        text_align='right',
    )

    output_txt = gr.Textbox(
        lines=5, 
        label="Output",
        type='text',
        rtl=True,  
        text_align='right',
    )

    btn = gr.Button(value="Shakkel")
    btn.click(diacritze, inputs=[input_txt, check_box], outputs=[output_txt])

if __name__ == "__main__":
    demo.queue().launch(
        # share=False,
        # debug=False,
        # server_port=7860,
        # server_name="0.0.0.0",
        # ssl_verify=False,
        # ssl_certfile="cert.pem",
        # ssl_keyfile="key.pem"
    )