David Kagramanyan
initial
ed13494
raw
history blame
1.97 kB
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)