Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,27 +10,54 @@ pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
|
10 |
r = requests.get("https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json")
|
11 |
data = json.loads(r.text)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
def predict(input):
|
16 |
|
17 |
out = pipe(input)[0]['translation_text']
|
18 |
raw = out
|
19 |
out = [x.strip() for x in out.split(" + ")]
|
20 |
|
21 |
-
output =
|
|
|
|
|
22 |
for o in out:
|
23 |
oo = [x.strip() for x in o.split("+")]
|
24 |
newout = []
|
25 |
for ooo in oo:
|
26 |
if ooo in data:
|
27 |
-
newout.append(f"
|
|
|
|
|
|
|
|
|
28 |
else:
|
29 |
newout.append(ooo)
|
30 |
-
|
31 |
-
output += "+".join(newout) + " | "
|
32 |
|
33 |
-
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
gr.Interface(predict, "textbox", "html", title="Ammiya Tokenizer", description="Tokenize Ammiya text and show Playaling words").launch()
|
|
|
10 |
r = requests.get("https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json")
|
11 |
data = json.loads(r.text)
|
12 |
|
13 |
+
# build gradio interface
|
|
|
14 |
def predict(input):
|
15 |
|
16 |
out = pipe(input)[0]['translation_text']
|
17 |
raw = out
|
18 |
out = [x.strip() for x in out.split(" + ")]
|
19 |
|
20 |
+
output = f"""
|
21 |
+
<div style='direction: rtl; text-align: right; font-size: 20px; font-family: sans-serif; line-height: 1.5'>{raw}<br><br>"""
|
22 |
+
|
23 |
for o in out:
|
24 |
oo = [x.strip() for x in o.split("+")]
|
25 |
newout = []
|
26 |
for ooo in oo:
|
27 |
if ooo in data:
|
28 |
+
newout.append(f"""
|
29 |
+
<span style='color: green; font-family: "Courier New", Courier, monospace;'
|
30 |
+
onmouseover='showCard(event, "{data[ooo]['translation']}", "{data[ooo]['features']}")'
|
31 |
+
onmouseout='hideCard(event)'>{data[ooo]['word']}</span>
|
32 |
+
""")
|
33 |
else:
|
34 |
newout.append(ooo)
|
|
|
|
|
35 |
|
36 |
+
output += "+".join(newout) + " | "
|
37 |
|
38 |
+
output += "</div>"
|
39 |
+
|
40 |
+
output += """
|
41 |
+
<div id='hovercard' style='position: absolute; visibility: hidden; background: white; padding: 10px;
|
42 |
+
border: 1px solid black; border-radius: 5px;'>
|
43 |
+
<h3 id='card_title'></h3>
|
44 |
+
<p id='card_content'></p>
|
45 |
+
</div>
|
46 |
+
<script>
|
47 |
+
function showCard(event, title, content) {
|
48 |
+
document.getElementById('hovercard').style.visibility = 'visible';
|
49 |
+
document.getElementById('hovercard').style.top = event.pageY + 'px';
|
50 |
+
document.getElementById('hovercard').style.left = event.pageX + 'px';
|
51 |
+
document.getElementById('card_title').innerText = title;
|
52 |
+
document.getElementById('card_content').innerText = content;
|
53 |
+
}
|
54 |
+
|
55 |
+
function hideCard(event) {
|
56 |
+
document.getElementById('hovercard').style.visibility = 'hidden';
|
57 |
+
}
|
58 |
+
</script>
|
59 |
+
"""
|
60 |
+
|
61 |
+
return output
|
62 |
|
63 |
gr.Interface(predict, "textbox", "html", title="Ammiya Tokenizer", description="Tokenize Ammiya text and show Playaling words").launch()
|