Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from transformers import pipeline
|
2 |
import requests
|
3 |
import json
|
|
|
4 |
|
5 |
pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
6 |
|
@@ -9,23 +10,26 @@ pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
|
9 |
r = requests.get("https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json")
|
10 |
data = json.loads(r.text)
|
11 |
|
12 |
-
|
13 |
# built gradio interface
|
14 |
-
import gradio as gr
|
15 |
|
16 |
def predict(input):
|
17 |
|
18 |
out = pipe(input)[0]['translation_text']
|
19 |
-
out = [x.strip() for x in out.split("+")]
|
20 |
|
21 |
-
output = ""
|
22 |
for o in out:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
|
31 |
gr.Interface(predict, "textbox", "html", title="Ammiya Tokenizer", description="Tokenize Ammiya text and show Playaling words").launch()
|
|
|
1 |
from transformers import pipeline
|
2 |
import requests
|
3 |
import json
|
4 |
+
import gradio as gr
|
5 |
|
6 |
pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
7 |
|
|
|
10 |
r = requests.get("https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json")
|
11 |
data = json.loads(r.text)
|
12 |
|
|
|
13 |
# built gradio interface
|
|
|
14 |
|
15 |
def predict(input):
|
16 |
|
17 |
out = pipe(input)[0]['translation_text']
|
18 |
+
out = [x.strip() for x in out.split(" + ")]
|
19 |
|
20 |
+
output = "<div style='direction: rtl; text-align: right; font-size: 20px; font-family: sans-serif; line-height: 1.5'>"
|
21 |
for o in out:
|
22 |
+
oo = [x.strip() for x in o.split("+")]
|
23 |
+
newout = []
|
24 |
+
for ooo in oo:
|
25 |
+
if ooo in data:
|
26 |
+
newout.append(f"<span style='color: green' title='{data[ooo]['translation']}\n{data[ooo]['features']}'>{data[ooo]['word']}</span>")
|
27 |
+
else:
|
28 |
+
newout.append(ooo)
|
29 |
+
|
30 |
+
output += "+".join(newout) + " | "
|
31 |
+
|
32 |
+
return output[:-3] + "</div>"
|
33 |
|
34 |
|
35 |
gr.Interface(predict, "textbox", "html", title="Ammiya Tokenizer", description="Tokenize Ammiya text and show Playaling words").launch()
|