Spaces:
Runtime error
Runtime error
Upload 11 files
Browse files- .gitignore +2 -0
- README.md +88 -10
- app.py +36 -30
- requirements.txt +1 -1
- sign2img.py +8 -3
- text2sign.py +17 -16
.gitignore
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
text2sign/
|
| 2 |
text2gloss/
|
| 3 |
__pycache__/
|
|
|
|
|
|
|
|
|
| 1 |
text2sign/
|
| 2 |
text2gloss/
|
| 3 |
__pycache__/
|
| 4 |
+
text2sign.zip
|
| 5 |
+
text2gloss.zip
|
README.md
CHANGED
|
@@ -1,10 +1,88 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SignBridge Server
|
| 2 |
+
|
| 3 |
+
Server/Backend for SignBridge App
|
| 4 |
+
|
| 5 |
+
# Docs
|
| 6 |
+
|
| 7 |
+
* Base URL
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
https://bipinkrish-signbridge.hf.space
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
### 1. Text to Sign
|
| 14 |
+
|
| 15 |
+
Takes a spoken text as input and returns fsw string which represents ham notation.
|
| 16 |
+
|
| 17 |
+
* Link
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
<base_url>/text2sign
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
* Params
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
text
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
* Example
|
| 30 |
+
|
| 31 |
+
```
|
| 32 |
+
https://bipinkrish-signbridge.hf.space/text2sign?text=today
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
```
|
| 36 |
+
{"sign": "M530x518S19a30500x482S19a38465x481S22f04509x506S22f14467x504"}
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### 2. Sign to Image
|
| 40 |
+
|
| 41 |
+
Takes a fsw string as input and returns image of ham notation.
|
| 42 |
+
|
| 43 |
+
* Link
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
<base_url>/sign2img
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
* Params
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
sign
|
| 53 |
+
line_color (Optional)
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
* Example
|
| 57 |
+
|
| 58 |
+
```
|
| 59 |
+
https://bipinkrish-signbridge.hf.space/sign2img?sign=M530x518S19a30500x482S19a38465x481S22f04509x506S22f14467x504&line_color=10,23,122,255
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+

|
| 63 |
+
|
| 64 |
+
### 3. Text to Gloss
|
| 65 |
+
|
| 66 |
+
Takes a spoken english text as input and returns simplified gloss of it.
|
| 67 |
+
|
| 68 |
+
* Link
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
<base_url>/text2gloss
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
* Params
|
| 75 |
+
|
| 76 |
+
```
|
| 77 |
+
text
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
* Example
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
https://bipinkrish-signbridge.hf.space/text2gloss?text=membership%20of%20parliament%20see%20minutes
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
```
|
| 87 |
+
{"gloss":"parliament see minute"}
|
| 88 |
+
```
|
app.py
CHANGED
|
@@ -9,55 +9,57 @@ warnings.filterwarnings("ignore")
|
|
| 9 |
try:
|
| 10 |
import text2sign
|
| 11 |
except Exception as e:
|
| 12 |
-
print(e)
|
| 13 |
|
| 14 |
|
| 15 |
############ for pickle ############
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
data_src = None
|
| 23 |
-
data_trg = None
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
preOpt = PreSettings()
|
| 33 |
-
src_lang_model = spacy.load(preOpt.lang_src)
|
| 34 |
-
trg_lang_model = spacy.load(preOpt.lang_trg)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
def tokenize_src(text):
|
| 42 |
-
for w in STOP_WORDS:
|
| 43 |
-
text = text.replace(w, '')
|
| 44 |
-
return [tok.text for tok in src_lang_model.tokenizer(text)]
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
def tokenize_trg(text):
|
| 48 |
-
for w in STOP_WORDS:
|
| 49 |
-
text = text.replace(w, '')
|
| 50 |
-
return [tok.text for tok in trg_lang_model.tokenizer(text)]
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
def filter_examples_with_length(x):
|
| 54 |
-
return len(vars(x)['src']) <= MAX_LEN and len(vars(x)['trg']) <= MAX_LEN
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
try:
|
| 58 |
import text2gloss
|
| 59 |
except Exception as e:
|
| 60 |
-
print(e)
|
| 61 |
|
| 62 |
####################
|
| 63 |
|
|
@@ -81,12 +83,16 @@ def translate_text():
|
|
| 81 |
@route("/sign2img")
|
| 82 |
def convert_text():
|
| 83 |
sign = request.query.get("sign", None)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
if not sign:
|
| 85 |
response.status = 400
|
| 86 |
return {"error": "No sign provided"}
|
| 87 |
|
| 88 |
try:
|
| 89 |
-
img = sign2img.convert(sign)
|
| 90 |
response.content_type = 'image/png'
|
| 91 |
return img
|
| 92 |
except Exception as e:
|
|
|
|
| 9 |
try:
|
| 10 |
import text2sign
|
| 11 |
except Exception as e:
|
| 12 |
+
print("text2sign", e)
|
| 13 |
|
| 14 |
|
| 15 |
############ for pickle ############
|
| 16 |
|
| 17 |
+
try:
|
| 18 |
+
class PreSettings:
|
| 19 |
+
lang_src = "en"
|
| 20 |
+
lang_trg = "en"
|
| 21 |
+
save_data = "text2gloss_data.pkl"
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
data_src = None
|
| 24 |
+
data_trg = None
|
| 25 |
|
| 26 |
+
max_len = 100
|
| 27 |
+
min_word_count = 3
|
| 28 |
|
| 29 |
+
keep_case = False
|
| 30 |
+
share_vocab = True
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
preOpt = PreSettings()
|
| 34 |
+
src_lang_model = spacy.load(preOpt.lang_src)
|
| 35 |
+
trg_lang_model = spacy.load(preOpt.lang_trg)
|
| 36 |
|
| 37 |
+
STOP_WORDS = ['X-', 'DESC-']
|
| 38 |
+
MAX_LEN = preOpt.max_len
|
| 39 |
+
MIN_FREQ = preOpt.min_word_count
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
def tokenize_src(text):
|
| 43 |
+
for w in STOP_WORDS:
|
| 44 |
+
text = text.replace(w, '')
|
| 45 |
+
return [tok.text for tok in src_lang_model.tokenizer(text)]
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
def tokenize_trg(text):
|
| 49 |
+
for w in STOP_WORDS:
|
| 50 |
+
text = text.replace(w, '')
|
| 51 |
+
return [tok.text for tok in trg_lang_model.tokenizer(text)]
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
def filter_examples_with_length(x):
|
| 55 |
+
return len(vars(x)['src']) <= MAX_LEN and len(vars(x)['trg']) <= MAX_LEN
|
| 56 |
+
except Exception as e:
|
| 57 |
+
print("text2gloss", e)
|
| 58 |
|
| 59 |
try:
|
| 60 |
import text2gloss
|
| 61 |
except Exception as e:
|
| 62 |
+
print("text2gloss", e)
|
| 63 |
|
| 64 |
####################
|
| 65 |
|
|
|
|
| 83 |
@route("/sign2img")
|
| 84 |
def convert_text():
|
| 85 |
sign = request.query.get("sign", None)
|
| 86 |
+
line_color = request.query.get("line_color", None)
|
| 87 |
+
if line_color:
|
| 88 |
+
line_color = tuple([int(x) for x in line_color.split(",")])
|
| 89 |
+
|
| 90 |
if not sign:
|
| 91 |
response.status = 400
|
| 92 |
return {"error": "No sign provided"}
|
| 93 |
|
| 94 |
try:
|
| 95 |
+
img = sign2img.convert(sign, line_color)
|
| 96 |
response.content_type = 'image/png'
|
| 97 |
return img
|
| 98 |
except Exception as e:
|
requirements.txt
CHANGED
|
@@ -4,7 +4,7 @@ bottle
|
|
| 4 |
torch==1.10.0
|
| 5 |
sockeye==3.0.13
|
| 6 |
numpy==1.19.0
|
| 7 |
-
git+https://github.com/sign-language-processing/signwriting.git
|
| 8 |
sentencepiece==0.2.0
|
| 9 |
# --pre -f https://dist.mxnet.io/python 'mxnet==2.0.0b20220206'
|
| 10 |
|
|
|
|
| 4 |
torch==1.10.0
|
| 5 |
sockeye==3.0.13
|
| 6 |
numpy==1.19.0
|
| 7 |
+
git+https://github.com/bipinkrish/signwriting-py.git # git+https://github.com/sign-language-processing/signwriting-py.git
|
| 8 |
sentencepiece==0.2.0
|
| 9 |
# --pre -f https://dist.mxnet.io/python 'mxnet==2.0.0b20220206'
|
| 10 |
|
sign2img.py
CHANGED
|
@@ -10,7 +10,12 @@ def to_bytes_io(image: Image) -> BytesIO:
|
|
| 10 |
return imgByte
|
| 11 |
|
| 12 |
|
| 13 |
-
def convert(fsw) -> BytesIO:
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return to_bytes_io(img)
|
|
|
|
| 10 |
return imgByte
|
| 11 |
|
| 12 |
|
| 13 |
+
def convert(fsw: str, line_color=None, fill_color=None) -> BytesIO:
|
| 14 |
+
if not line_color or len(line_color) != 4:
|
| 15 |
+
line_color = (0, 0, 0, 255)
|
| 16 |
+
|
| 17 |
+
if not fill_color or len(fill_color) != 4:
|
| 18 |
+
fill_color = (0, 0, 0, 0)
|
| 19 |
+
|
| 20 |
+
img: Image = signwriting_to_image(fsw, line_color=line_color, fill_color=fill_color)
|
| 21 |
return to_bytes_io(img)
|
text2sign.py
CHANGED
|
@@ -19,8 +19,23 @@ TRANS_TYPE = "sent"
|
|
| 19 |
N_BEST = 3
|
| 20 |
BEAM_SIZE = N_BEST
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
print(text)
|
| 25 |
|
| 26 |
tag_str = f"<2{LANG_CODE}> <4{CONT_CODE}> <{TRANS_TYPE}>"
|
|
@@ -32,20 +47,6 @@ def translate(text):
|
|
| 32 |
encoded = inference.make_input_from_plain_string(0, encoded)
|
| 33 |
print(encoded)
|
| 34 |
|
| 35 |
-
TRANSLATOR = inference.Translator(
|
| 36 |
-
context=DEVICE,
|
| 37 |
-
ensemble_mode="linear",
|
| 38 |
-
scorer=inference.CandidateScorer(),
|
| 39 |
-
output_scores=True,
|
| 40 |
-
batch_size=1,
|
| 41 |
-
beam_size=BEAM_SIZE,
|
| 42 |
-
beam_search_stop="all",
|
| 43 |
-
nbest_size=N_BEST,
|
| 44 |
-
models=MODELS,
|
| 45 |
-
source_vocabs=SRC_VOCABS,
|
| 46 |
-
target_vocabs=TARG_VOCABS,
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
output = TRANSLATOR.translate([encoded])[0]
|
| 50 |
print(output)
|
| 51 |
|
|
|
|
| 19 |
N_BEST = 3
|
| 20 |
BEAM_SIZE = N_BEST
|
| 21 |
|
| 22 |
+
TRANSLATOR = inference.Translator(
|
| 23 |
+
context=DEVICE,
|
| 24 |
+
ensemble_mode="linear",
|
| 25 |
+
scorer=inference.CandidateScorer(),
|
| 26 |
+
output_scores=True,
|
| 27 |
+
batch_size=1,
|
| 28 |
+
beam_size=BEAM_SIZE,
|
| 29 |
+
beam_search_stop="all",
|
| 30 |
+
nbest_size=N_BEST,
|
| 31 |
+
models=MODELS,
|
| 32 |
+
source_vocabs=SRC_VOCABS,
|
| 33 |
+
target_vocabs=TARG_VOCABS,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def translate(text: str):
|
| 38 |
+
text = text.lower()
|
| 39 |
print(text)
|
| 40 |
|
| 41 |
tag_str = f"<2{LANG_CODE}> <4{CONT_CODE}> <{TRANS_TYPE}>"
|
|
|
|
| 47 |
encoded = inference.make_input_from_plain_string(0, encoded)
|
| 48 |
print(encoded)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
output = TRANSLATOR.translate([encoded])[0]
|
| 51 |
print(output)
|
| 52 |
|