import requests import gradio as gr from shakkala import Shakkala tashkel_url = "http://www.7koko.com/api/tashkil/index.php" def add_tashkeel1(text): data = {"textArabic": text} response = requests.post(tashkel_url, data=data) response.encoding = "utf-8" text = response.text.strip() return text sh = Shakkala(version=3) model, graph = sh.get_model() def add_tashkeel2(input_text): input_int = sh.prepare_input(input_text) logits = model.predict(input_int)[0] predicted_harakat = sh.logits_to_text(logits) final_output = sh.get_final_text(input_text, predicted_harakat) print(final_output) return final_output with gr.Blocks(title="Arabic Tashkeel") as demo: gr.HTML("

Arabic Tashkeel

") gr.HTML( "

Compare different methods for adding tashkeel to Arabic text.

" ) with gr.Tab(label="Tashkil"): with gr.Row(): with gr.Column(): text_input1 = gr.Textbox( lines=1, label="Input Text", rtl=True, text_align="right" ) with gr.Row(): clear_button1 = gr.Button(value="Clear", variant="secondary") submit_button1 = gr.Button(value="Add Tashkeel", variant="primary") with gr.Column(): text_output1 = gr.Textbox( lines=1, label="Output Text", rtl=True, text_align="right" ) submit_button1.click(add_tashkeel1, inputs=text_input1, outputs=text_output1) clear_button1.click(lambda: text_input1.update("")) with gr.Tab(label="Shakkala"): with gr.Row(): with gr.Column(): text_input2 = gr.Textbox( lines=1, label="Input Text", rtl=True, text_align="right" ) with gr.Row(): clear_button2 = gr.Button(value="Clear", variant="secondary") submit_button2 = gr.Button( value="Apply Tashkeel", variant="primary" ) with gr.Column(): text_output2 = gr.Textbox( lines=1, label="Output Text", rtl=True, text_align="right" ) submit_button2.click(add_tashkeel2, inputs=text_input2, outputs=text_output2) clear_button2.click(lambda: text_input2.update("")) demo.queue().launch()