Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import gradio as gr
|
|
| 6 |
pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
| 7 |
|
| 8 |
# download json and open
|
| 9 |
-
# from https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json
|
| 10 |
r = requests.get("https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json")
|
| 11 |
data = json.loads(r.text)
|
| 12 |
|
|
@@ -18,7 +17,7 @@ def predict(input):
|
|
| 18 |
out = [x.strip() for x in out.split(" + ")]
|
| 19 |
|
| 20 |
output = f"""
|
| 21 |
-
|
| 22 |
|
| 23 |
for o in out:
|
| 24 |
oo = [x.strip() for x in o.split("+")]
|
|
@@ -26,9 +25,8 @@ def predict(input):
|
|
| 26 |
for ooo in oo:
|
| 27 |
if ooo in data:
|
| 28 |
newout.append(f"""
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
onmouseout='hideCard(event)'>{data[ooo]['word']}</span>
|
| 32 |
""")
|
| 33 |
else:
|
| 34 |
newout.append(ooo)
|
|
@@ -38,26 +36,13 @@ def predict(input):
|
|
| 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 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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()
|
|
|
|
| 6 |
pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
| 7 |
|
| 8 |
# download json and open
|
|
|
|
| 9 |
r = requests.get("https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json")
|
| 10 |
data = json.loads(r.text)
|
| 11 |
|
|
|
|
| 17 |
out = [x.strip() for x in out.split(" + ")]
|
| 18 |
|
| 19 |
output = f"""
|
| 20 |
+
<div style='direction: rtl; text-align: right; font-size: 20px; font-family: sans-serif; line-height: 1.5'>{raw}<br><br>"""
|
| 21 |
|
| 22 |
for o in out:
|
| 23 |
oo = [x.strip() for x in o.split("+")]
|
|
|
|
| 25 |
for ooo in oo:
|
| 26 |
if ooo in data:
|
| 27 |
newout.append(f"""
|
| 28 |
+
<span style='color: green; font-family: "Courier New", Courier, monospace;'
|
| 29 |
+
data-toggle='tooltip' data-placement='top' title='{data[ooo]['translation']}\n{data[ooo]['features']}'>{data[ooo]['word']}</span>
|
|
|
|
| 30 |
""")
|
| 31 |
else:
|
| 32 |
newout.append(ooo)
|
|
|
|
| 36 |
output += "</div>"
|
| 37 |
|
| 38 |
output += """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
<script>
|
| 40 |
+
$(document).ready(function(){
|
| 41 |
+
$('[data-toggle="tooltip"]').tooltip();
|
| 42 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
</script>
|
| 44 |
"""
|
| 45 |
|
| 46 |
return output
|
| 47 |
|
| 48 |
+
gr.Interface(predict, "textbox", "html", title="Ammiya Tokenizer", description="Tokenize Ammiya text and show Playaling words").launch()
|