-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add utility server implementation
- Loading branch information
Showing
7 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from signwriting.fingerspelling.fingerspelling import spell | ||
from signwriting.mouthing.mouthing import mouth | ||
from signwriting.utils.join_signs import join_signs_vertical | ||
|
||
text = "Hello SignWriting List" | ||
for word in text.split(" "): | ||
mouthing = mouth(word, language="eng-Latn") | ||
spelling = spell(word, language="en-us-ase-asl", vertical=False) | ||
sign = join_signs_vertical(mouthing, spelling, spacing=5) | ||
print(sign) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from flask_restful import Resource, reqparse | ||
|
||
from signwriting.fingerspelling.fingerspelling import spell, get_chars_by | ||
|
||
parser = reqparse.RequestParser() | ||
parser.add_argument('text', type=str, required=True, help='Text to fingerspell') | ||
parser.add_argument('signed_language', type=str, required=True, help='Signed language ISO-3 code') | ||
|
||
|
||
class Fingerspelling(Resource): | ||
def get(self): | ||
args = parser.parse_args() | ||
|
||
try: | ||
chars = get_chars_by(value=args["signed_language"], category="SIGNED") | ||
except ValueError as e: | ||
return {"message": str(e)}, 400 | ||
|
||
return {"fsw": spell(args["text"], chars=chars)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from flask_restful import Resource, reqparse | ||
|
||
from signwriting.mouthing.mouthing import mouth | ||
|
||
parser = reqparse.RequestParser() | ||
parser.add_argument('text', type=str, required=True, help='Text to mouth') | ||
parser.add_argument('spoken_language', type=str, required=True, | ||
help='Spoken Language code. See "Language Support" at https://pypi.org/project/epitran/') | ||
|
||
|
||
class Mouthing(Resource): | ||
def get(self): | ||
args = parser.parse_args() | ||
|
||
return {"fsw": mouth(args["text"], language=args["spoken_language"])} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from flask import Flask | ||
from flask_restful import Api | ||
|
||
from signwriting.fingerspelling.server import Fingerspelling | ||
from signwriting.mouthing.server import Mouthing | ||
from signwriting.visualizer.server import Visualizer | ||
|
||
app = Flask(__name__) | ||
api = Api(app) | ||
|
||
api.add_resource(Visualizer, '/visualizer') | ||
api.add_resource(Fingerspelling, '/fingerspelling') | ||
api.add_resource(Mouthing, '/mouthing') | ||
|
||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from io import BytesIO | ||
|
||
from flask import send_file | ||
from flask_restful import Resource, reqparse | ||
|
||
from signwriting.formats.swu_to_fsw import swu2fsw | ||
from signwriting.visualizer.visualize import RGBA, signwriting_to_image | ||
|
||
|
||
def hex_color_to_rgba(hex_color: str) -> RGBA: | ||
r = int(hex_color[0:2], 16) | ||
g = int(hex_color[2:4], 16) | ||
b = int(hex_color[4:6], 16) | ||
a = int(hex_color[6:8], 16) if len(hex_color) > 6 else 255 | ||
return r, g, b, a | ||
|
||
|
||
def send_pil_image(pil_img): | ||
img_io = BytesIO() | ||
pil_img.save(img_io, 'PNG') | ||
img_io.seek(0) | ||
return send_file(img_io, mimetype='image/png') | ||
|
||
|
||
parser = reqparse.RequestParser() | ||
parser.add_argument('fsw', type=str, required=False, help='FSW String (Must be provided if swu is not provided)') | ||
parser.add_argument('swu', type=str, required=False, help='SWU String (Must be provided if fsw is not provided)') | ||
parser.add_argument('line', type=str, default='000000ff', help='Line color in hex format') | ||
parser.add_argument('fill', type=str, default='ffffffff', help='Fill color in hex format') | ||
|
||
|
||
class Visualizer(Resource): | ||
def get(self): | ||
args = parser.parse_args() | ||
fsw = args.get("fsw") | ||
swu = args.get("swu") | ||
if fsw is None and swu is None: | ||
return {"message": "No fsw or swu provided"}, 400 | ||
|
||
line_color = hex_color_to_rgba(args["line"]) | ||
fill_color = hex_color_to_rgba(args["fill"]) | ||
|
||
sw_string = fsw if fsw is not None else swu2fsw(swu) | ||
image = signwriting_to_image(fsw=sw_string, line_color=line_color, fill_color=fill_color) | ||
return send_pil_image(image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters