Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
pipe = pipeline("translation", "guymorlan/TokenizerLabeller")
|
| 6 |
+
|
| 7 |
+
# download json and open
|
| 8 |
+
# from https://huggingface.co/guymorlan/TokenizerLabeller/raw/main/playaling_words.json
|
| 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 |
+
if o in data:
|
| 24 |
+
output += f"<span style='color: green' title='{data[o]['translation']}\n{data[o]['features']}'>{data[o]['word']}</span> "
|
| 25 |
+
else:
|
| 26 |
+
output += o + " "
|
| 27 |
+
|
| 28 |
+
return output
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
gr.Interface(predict, "textbox", "html", title="Ammiya Tokenizer", description="Tokenize Ammiya text and show Playaling words").launch()
|