HamzaNaser commited on
Commit
61cbae8
·
verified ·
1 Parent(s): 058cd82

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dialects by Region.png +0 -0
  2. app.py +86 -16
Dialects by Region.png ADDED
app.py CHANGED
@@ -1,6 +1,8 @@
1
 
2
  import requests
3
  import time
 
 
4
 
5
 
6
  hold_time = time.time()
@@ -11,6 +13,8 @@ headers = {
11
  "Content-Type": "application/json"
12
  }
13
 
 
 
14
  def query(payload):
15
  global hold_time
16
  response = requests.post(API_URL, headers=headers, json=payload)
@@ -22,46 +26,112 @@ def query(payload):
22
  return response.json()
23
 
24
 
25
- def run_model(text):
26
  global hold_time
27
  output = query({
28
- "inputs": text,
29
  "parameters": {}
30
  })
31
  if output:
32
  hold_time = 1
33
  return output[0]['generated_text']
34
  else:
35
- return f'Model is being loaded, please try again in {int((hold_time - time.time()) + 35)} seconds.'
 
 
 
 
36
 
37
 
38
 
39
 
40
- run_model('السلام عيكم')
41
-
42
- time.sleep(35)
43
-
44
-
45
 
 
46
 
47
 
48
- import gradio as gr
49
-
50
- examples = [
51
  ["ما ابغا أروح الإمتحان"],
52
  ["أييد أن انام ف لبيتنا"],
53
- ["Hello how are you today"]
 
54
  ]
55
 
 
56
  def mode_run(text):
57
  result = run_model(text)
58
  return result
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- demo = gr.Interface(fn=mode_run,
62
- inputs="text",
63
- outputs="text",
64
- examples=examples)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  demo.launch()
67
 
 
1
 
2
  import requests
3
  import time
4
+ from PIL import Image
5
+ import gradio as gr
6
 
7
 
8
  hold_time = time.time()
 
13
  "Content-Type": "application/json"
14
  }
15
 
16
+
17
+
18
  def query(payload):
19
  global hold_time
20
  response = requests.post(API_URL, headers=headers, json=payload)
 
26
  return response.json()
27
 
28
 
29
+ def run_model(Dialects):
30
  global hold_time
31
  output = query({
32
+ "inputs": Dialects,
33
  "parameters": {}
34
  })
35
  if output:
36
  hold_time = 1
37
  return output[0]['generated_text']
38
  else:
39
+ wait_time = int((hold_time - time.time()) + 35)
40
+ if wait_time <= 0:
41
+ return f'Model is being loaded, please try again in {wait_time} seconds.'
42
+ else:
43
+ return 'Taking longer than usual to load please wait or refresh the page.'
44
 
45
 
46
 
47
 
48
+ # run_model('السلام عيكم')
 
 
 
 
49
 
50
+ # time.sleep(35)
51
 
52
 
53
+ examples_text = [
 
 
54
  ["ما ابغا أروح الإمتحان"],
55
  ["أييد أن انام ف لبيتنا"],
56
+ ["Hello how are you today"],
57
+ ["kef al7al"]
58
  ]
59
 
60
+
61
  def mode_run(text):
62
  result = run_model(text)
63
  return result
64
 
65
+ link = '<a href="{}" target="_blank" style="cursor: pointer; font-size: 18px;">{}</a>'
66
+
67
+ with gr.Blocks(theme=gr.themes.GoogleFont('ali')) as demo:
68
+
69
+
70
+
71
+ gr.Markdown(
72
+ """
73
+ ## Dialects to MSA transformer
74
+ Start typing Non-Traditional Arabic to convert into Classical version.
75
+ """
76
+ )
77
+
78
+ with gr.Row():
79
+ with gr.Column():
80
+ input = gr.Textbox(label='Dialects')
81
+ with gr.Column():
82
+ output = gr.Textbox(label='MSA')
83
+
84
+
85
+
86
+ with gr.Row():
87
+ button = gr.Button('Submit',variant='primary')
88
+ clear = gr.ClearButton(input)
89
+
90
+
91
+ examples = gr.Examples(examples_text,input)
92
+
93
+
94
+ with gr.Row():
95
+ gr.Markdown(
96
+ """
97
+ ## Model Overview
98
+ This Model is optimized to convert written text in various non Standard Classical Arabic into Classic Arabic, the model was Fine-Tuned on 0.8M pairs of sentence generated by OpenAI API gpt-4o-mini Text Generation Model, beside being able to convert Dialects into Classical Arabic, the model can also be used in other NLP tasks such as Text Correction, Diacretization and Sentence Punctuation.
99
+ """
100
+ )
101
+
102
+
103
+
104
 
105
+ with gr.Row():
106
+ gr.Markdown(
107
+ """
108
+ ## Dielcts the Model trained on
109
+ Below image shows an estimate of dialects the model trained on.
110
+ """
111
+ )
112
+ with gr.Row():
113
+ with gr.Column(scale=3):
114
+ gr.Image(Image.open('Dialects by Region.png'),height=300,container=False)
115
+ with gr.Column(scale=3):
116
+ pass
117
+
118
+
119
+
120
+ with gr.Row():
121
+ with gr.Column(scale=1):
122
+ pass
123
+ with gr.Column(scale=2):
124
+ gr.HTML(
125
+ '<div style="text-align: center;">' +\
126
+ link.format('https://huggingface.co/HamzaNaser/Dialects-to-MSA-Transformer', 'Model Card') + ' -- '+link.format('https://www.linkedin.com/in/hamza-naser-0b4b90160/', 'LinkedIn') +\
127
+ '</div>'
128
+ )
129
+ with gr.Column(scale=1):
130
+ pass
131
+
132
+
133
+ input.submit(mode_run,input,output)
134
+ button.click(mode_run,input,output)
135
 
136
  demo.launch()
137