File size: 1,974 Bytes
ed13494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers.utils import logging
import time
import joblib
import re
import numpy as np
from transformers.utils import logging

from src import get_lexical_desc,get_morphemic_desc, preprocess

logging.set_verbosity_info()
logger = logging.get_logger("transformers")


def classify(input_text_message: str):

    logger.info(time.strftime("%Y.%m.%d, %H:%M:%S")+' '+'input text message: '+input_text_message)

    words=preprocess(input_text_message)
    desc_lexical=get_lexical_desc(words).reshape((1,-1))
    desc_morphemic=get_morphemic_desc(words).reshape((1,-1))

    data=np.concatenate([desc_morphemic,desc_lexical],axis=1)
    prediction=loaded_rf.predict_proba(data)[0]

    confidences = {labels[i]: float(prediction[i]) for i in range(3)}

    return confidences

labels = ['eastern armenian', 'western armenian', 'grabar (classic) armenian']

loaded_rf = joblib.load("rfc_30_0.95.joblib")

text='western - Աստուած ըսաւ. «Մեր պատկերով, մեր նմանութեան պէս մարդ ընենք, որ տիրապետէն ծովու ձուկերուն, երկինքի թռչուններուն եւ ընտանի անասուններուն, ամբողջ երկրին, ու երկրի վրայ ըսողացող բոլոր սողուններուն».* 27 Աստուած իր պատկերով ստեղծեց մարդը'

examples=[text]

with gr.Blocks() as demo:
    gr.Markdown("Check your text for compliance with the NVC rules")


    with gr.Tab("Text analysis"):
        text_input = gr.Textbox(lines=2, placeholder="Enter your text here")
        text_button = gr.Button("Define dialect group")
        examples_block = gr.Examples(examples=examples,
                                     inputs=[text_input], )

        rec_output = gr.Label(label='Labels', num_top_classes=3)

        text_button.click(classify, inputs=text_input,
                          outputs=[rec_output])


demo.launch(share=False, debug=True)