MohamedRashad commited on
Commit
7efa162
1 Parent(s): b36fd77
Files changed (2) hide show
  1. app.py +62 -4
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,14 +1,72 @@
1
  import requests
2
  import gradio as gr
 
3
 
4
  tashkel_url = "http://www.7koko.com/api/tashkil/index.php"
5
 
6
- def add_tashkeel(text):
 
7
  data = {"textArabic": text}
8
  response = requests.post(tashkel_url, data=data)
9
- response.encoding = 'utf-8'
10
  text = response.text.strip()
11
  return text
12
 
13
- demo = gr.Interface(fn=add_tashkeel, inputs="text", outputs="text")
14
- demo.queue().launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
  import gradio as gr
3
+ from shakkala import Shakkala
4
 
5
  tashkel_url = "http://www.7koko.com/api/tashkil/index.php"
6
 
7
+
8
+ def add_tashkeel1(text):
9
  data = {"textArabic": text}
10
  response = requests.post(tashkel_url, data=data)
11
+ response.encoding = "utf-8"
12
  text = response.text.strip()
13
  return text
14
 
15
+
16
+ sh = Shakkala(version=3)
17
+ model, graph = sh.get_model()
18
+
19
+
20
+ def add_tashkeel2(input_text):
21
+ input_int = sh.prepare_input(input_text)
22
+ logits = model.predict(input_int)[0]
23
+ predicted_harakat = sh.logits_to_text(logits)
24
+ final_output = sh.get_final_text(input_text, predicted_harakat)
25
+ print(final_output)
26
+ return final_output
27
+
28
+
29
+ with gr.Blocks(title="Arabic Tashkeel") as demo:
30
+ gr.HTML("<center><h1>Arabic Tashkeel</h1></center>")
31
+ gr.HTML(
32
+ "<center><p>Compare different methods for adding tashkeel to Arabic text.</p></center>"
33
+ )
34
+ with gr.Tab(label="Tashkil"):
35
+ with gr.Row():
36
+ with gr.Column():
37
+ text_input1 = gr.Textbox(
38
+ lines=1, label="Input Text", rtl=True, text_align="right"
39
+ )
40
+ with gr.Row():
41
+ clear_button1 = gr.Button(value="Clear", variant="secondary")
42
+ submit_button1 = gr.Button(value="Add Tashkeel", variant="primary")
43
+
44
+ with gr.Column():
45
+ text_output1 = gr.Textbox(
46
+ lines=1, label="Output Text", rtl=True, text_align="right"
47
+ )
48
+
49
+ submit_button1.click(add_tashkeel1, inputs=text_input1, outputs=text_output1)
50
+ clear_button1.click(lambda: text_input1.update(""))
51
+
52
+ with gr.Tab(label="Shakkala"):
53
+ with gr.Row():
54
+ with gr.Column():
55
+ text_input2 = gr.Textbox(
56
+ lines=1, label="Input Text", rtl=True, text_align="right"
57
+ )
58
+ with gr.Row():
59
+ clear_button2 = gr.Button(value="Clear", variant="secondary")
60
+ submit_button2 = gr.Button(
61
+ value="Apply Tashkeel", variant="primary"
62
+ )
63
+
64
+ with gr.Column():
65
+ text_output2 = gr.Textbox(
66
+ lines=1, label="Output Text", rtl=True, text_align="right"
67
+ )
68
+
69
+ submit_button2.click(add_tashkeel2, inputs=text_input2, outputs=text_output2)
70
+ clear_button2.click(lambda: text_input2.update(""))
71
+
72
+ demo.queue().launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  requests
2
- gradio
 
 
1
  requests
2
+ gradio
3
+ shakkala