guymorlan commited on
Commit
af7d479
·
verified ·
1 Parent(s): 5e89577

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -10,11 +10,9 @@ async () => {
10
  document.getElementById('card_title').innerText = title;
11
  document.getElementById('card_content').innerText = content;
12
  }
13
-
14
  function hideCard(event) {
15
  document.getElementById('hovercard').style.visibility = 'hidden';
16
  }
17
-
18
  globalThis.showCard = showCard;
19
  globalThis.hideCard = hideCard;
20
  }
@@ -34,7 +32,6 @@ def get_matches(text):
34
  # only keep tuples with length 2
35
  mapping = [x for x in mapping if len(x) == 2]
36
 
37
-
38
  matches = []
39
  cur = mapping.pop(0)
40
  i = 0
@@ -69,14 +66,12 @@ def predict(input):
69
  i = 0
70
  while i < len(text):
71
  if i in matches:
72
-
73
  match = matches[i]["lexicon"]
74
  # if match ends with _R, remove _R suffix
75
  if match.endswith("_R"):
76
  match = match[:-2]
77
 
78
  if match in data:
79
- # match = matches[i]["lexicon"]
80
  output += f"""
81
  <span style='background-color: #4CAF50; color: #FFFFFF; border: 1px solid #4CAF50; border-radius: 5px; font-family: "Courier New", Courier, monospace;'
82
  onmouseover='showCard(event, "{data[match]['translation']}", "{data[match]['features']}")'
@@ -86,9 +81,8 @@ def predict(input):
86
  output += matches[i]["match"]
87
  i = matches[i]["end"]
88
  else:
89
- print(f"'{text[i]}'")
90
  if text[i] == " ":
91
- output += "&nbsp"
92
  else:
93
  output += text[i]
94
  i += 1
@@ -109,13 +103,15 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Ammiya Tokenizer and Labeler") as
109
  with gr.Row():
110
  with gr.Column():
111
  input = gr.Textbox(label="Input", placeholder="Enter English Text", lines=1)
112
- gr.Examples(["بديش اروح معك", "معملتش اشي"], input)
113
- btn = gr.Button(label="Analyze")
114
  with gr.Column():
115
  with gr.Box():
116
  html = gr.HTML()
117
  btn.click(predict, inputs=[input], outputs=[html])
118
- input.submit(predict, inputs = [input], outputs=[html])
119
 
120
  demo.load(_js=js)
 
 
121
  demo.launch()
 
10
  document.getElementById('card_title').innerText = title;
11
  document.getElementById('card_content').innerText = content;
12
  }
 
13
  function hideCard(event) {
14
  document.getElementById('hovercard').style.visibility = 'hidden';
15
  }
 
16
  globalThis.showCard = showCard;
17
  globalThis.hideCard = hideCard;
18
  }
 
32
  # only keep tuples with length 2
33
  mapping = [x for x in mapping if len(x) == 2]
34
 
 
35
  matches = []
36
  cur = mapping.pop(0)
37
  i = 0
 
66
  i = 0
67
  while i < len(text):
68
  if i in matches:
 
69
  match = matches[i]["lexicon"]
70
  # if match ends with _R, remove _R suffix
71
  if match.endswith("_R"):
72
  match = match[:-2]
73
 
74
  if match in data:
 
75
  output += f"""
76
  <span style='background-color: #4CAF50; color: #FFFFFF; border: 1px solid #4CAF50; border-radius: 5px; font-family: "Courier New", Courier, monospace;'
77
  onmouseover='showCard(event, "{data[match]['translation']}", "{data[match]['features']}")'
 
81
  output += matches[i]["match"]
82
  i = matches[i]["end"]
83
  else:
 
84
  if text[i] == " ":
85
+ output += "&nbsp;"
86
  else:
87
  output += text[i]
88
  i += 1
 
103
  with gr.Row():
104
  with gr.Column():
105
  input = gr.Textbox(label="Input", placeholder="Enter English Text", lines=1)
106
+ gr.Examples(examples=["بديش اروح معك", "معملتش اشي"], inputs=input)
107
+ btn = gr.Button("Analyze")
108
  with gr.Column():
109
  with gr.Box():
110
  html = gr.HTML()
111
  btn.click(predict, inputs=[input], outputs=[html])
112
+ input.submit(predict, inputs=[input], outputs=[html])
113
 
114
  demo.load(_js=js)
115
+
116
+ if __name__ == "__main__":
117
  demo.launch()