Spaces:
Running
Running
landmarks animation
Browse files- app.py +39 -12
- requirements.txt +1 -1
app.py
CHANGED
@@ -12,7 +12,7 @@ The text is preprocessed, tokenized and rearranged and then each token is mapped
|
|
12 |
|
13 |
> *NOTE*: This model only supports a fixed vocabulary. See the [`*-dictionary-mapping.json`](https://github.com/sign-language-translator/sign-language-datasets/tree/main/parallel_texts) files for supported words.
|
14 |
> This version needs to re-encode the generated video so that will take some extra time after translation.
|
15 |
-
> Since this is a rule-based model, you will have to add
|
16 |
""".strip()
|
17 |
|
18 |
TITLE = "Concatenative Synthesis: Rule Based Text to Sign Language Translator"
|
@@ -79,19 +79,26 @@ def text_to_video(
|
|
79 |
text: str,
|
80 |
text_language: str,
|
81 |
sign_language: str,
|
|
|
82 |
output_path: str = "output.mp4",
|
83 |
codec="h264", # ToDo: install h264 codec for opencv
|
84 |
):
|
85 |
translation_model.text_language = text_language
|
86 |
translation_model.sign_language = sign_language
|
|
|
|
|
|
|
87 |
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
90 |
|
91 |
# ToDo: video.watermark("Sign Language Translator\nAI Generated Video")
|
92 |
|
93 |
|
94 |
-
def translate(text: str, text_lang: str, sign_lang: str):
|
95 |
log = [
|
96 |
text,
|
97 |
text_lang,
|
@@ -101,7 +108,14 @@ def translate(text: str, text_lang: str, sign_lang: str):
|
|
101 |
]
|
102 |
try:
|
103 |
path = "output.mp4"
|
104 |
-
text_to_video(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
request_logger.flag(log)
|
106 |
return path
|
107 |
|
@@ -114,11 +128,11 @@ def translate(text: str, text_lang: str, sign_lang: str):
|
|
114 |
with gradio.Blocks(title=TITLE, head=CUSTOM_JS, css=CUSTOM_CSS) as gradio_app:
|
115 |
gradio.Markdown(f"# {TITLE}")
|
116 |
gradio.Markdown(DESCRIPTION)
|
117 |
-
with gradio.Row():
|
118 |
-
with gradio.Column():
|
119 |
gradio.Markdown("## Input Text")
|
120 |
with gradio.Row():
|
121 |
-
with gradio.Column():
|
122 |
gradio.Markdown("Write here (in selected language):")
|
123 |
source_textbox = gradio.Textbox(
|
124 |
lines=1,
|
@@ -127,7 +141,7 @@ with gradio.Blocks(title=TITLE, head=CUSTOM_JS, css=CUSTOM_CSS) as gradio_app:
|
|
127 |
show_copy_button=True,
|
128 |
elem_id="source-textbox",
|
129 |
)
|
130 |
-
with gradio.Column():
|
131 |
gradio.Markdown("Generate sample text instead:")
|
132 |
with gradio.Row():
|
133 |
language_model_dropdown = gradio.Dropdown(
|
@@ -168,9 +182,17 @@ with gradio.Blocks(title=TITLE, head=CUSTOM_JS, css=CUSTOM_CSS) as gradio_app:
|
|
168 |
value=slt.SignLanguageCodes.PAKISTAN_SIGN_LANGUAGE.value,
|
169 |
label="Sign Language",
|
170 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
# todo: sign format: video/landmarks (tabs?)
|
172 |
|
173 |
-
with gradio.Column():
|
174 |
gradio.Markdown("## Output Sign Language")
|
175 |
output_video = gradio.Video(
|
176 |
format="mp4",
|
@@ -180,11 +202,16 @@ with gradio.Blocks(title=TITLE, head=CUSTOM_JS, css=CUSTOM_CSS) as gradio_app:
|
|
180 |
include_audio=False,
|
181 |
)
|
182 |
|
183 |
-
with gradio.Row():
|
184 |
translate_button = gradio.Button("Translate", variant="primary")
|
185 |
translate_button.click(
|
186 |
translate,
|
187 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
188 |
outputs=[output_video],
|
189 |
api_name="translate",
|
190 |
)
|
|
|
12 |
|
13 |
> *NOTE*: This model only supports a fixed vocabulary. See the [`*-dictionary-mapping.json`](https://github.com/sign-language-translator/sign-language-datasets/tree/main/parallel_texts) files for supported words.
|
14 |
> This version needs to re-encode the generated video so that will take some extra time after translation.
|
15 |
+
> Since this is a rule-based model, you will have to add **context** to ambiguous words (e.g. glass(material) vs glass(container)).
|
16 |
""".strip()
|
17 |
|
18 |
TITLE = "Concatenative Synthesis: Rule Based Text to Sign Language Translator"
|
|
|
79 |
text: str,
|
80 |
text_language: str,
|
81 |
sign_language: str,
|
82 |
+
sign_format: str = "video",
|
83 |
output_path: str = "output.mp4",
|
84 |
codec="h264", # ToDo: install h264 codec for opencv
|
85 |
):
|
86 |
translation_model.text_language = text_language
|
87 |
translation_model.sign_language = sign_language
|
88 |
+
translation_model.sign_format = sign_format
|
89 |
+
if sign_format == "landmarks":
|
90 |
+
translation_model.sign_embedding_model = "mediapipe-world"
|
91 |
|
92 |
+
sign = translation_model.translate(text)
|
93 |
+
if isinstance(sign, slt.Landmarks):
|
94 |
+
sign.save_animation(output_path, overwrite=True)
|
95 |
+
else:
|
96 |
+
sign.save(output_path, overwrite=True, codec=codec)
|
97 |
|
98 |
# ToDo: video.watermark("Sign Language Translator\nAI Generated Video")
|
99 |
|
100 |
|
101 |
+
def translate(text: str, text_lang: str, sign_lang: str, sign_format: str):
|
102 |
log = [
|
103 |
text,
|
104 |
text_lang,
|
|
|
108 |
]
|
109 |
try:
|
110 |
path = "output.mp4"
|
111 |
+
text_to_video(
|
112 |
+
text,
|
113 |
+
text_lang,
|
114 |
+
sign_lang,
|
115 |
+
sign_format=sign_format,
|
116 |
+
output_path=path,
|
117 |
+
codec="mp4v",
|
118 |
+
)
|
119 |
request_logger.flag(log)
|
120 |
return path
|
121 |
|
|
|
128 |
with gradio.Blocks(title=TITLE, head=CUSTOM_JS, css=CUSTOM_CSS) as gradio_app:
|
129 |
gradio.Markdown(f"# {TITLE}")
|
130 |
gradio.Markdown(DESCRIPTION)
|
131 |
+
with gradio.Row(): # Inputs and Outputs
|
132 |
+
with gradio.Column(): # Inputs
|
133 |
gradio.Markdown("## Input Text")
|
134 |
with gradio.Row():
|
135 |
+
with gradio.Column(): # Source TextArea
|
136 |
gradio.Markdown("Write here (in selected language):")
|
137 |
source_textbox = gradio.Textbox(
|
138 |
lines=1,
|
|
|
141 |
show_copy_button=True,
|
142 |
elem_id="source-textbox",
|
143 |
)
|
144 |
+
with gradio.Column(): # Language Model
|
145 |
gradio.Markdown("Generate sample text instead:")
|
146 |
with gradio.Row():
|
147 |
language_model_dropdown = gradio.Dropdown(
|
|
|
182 |
value=slt.SignLanguageCodes.PAKISTAN_SIGN_LANGUAGE.value,
|
183 |
label="Sign Language",
|
184 |
)
|
185 |
+
output_format_dropdown = gradio.Dropdown(
|
186 |
+
choices=[
|
187 |
+
slt.SignFormatCodes.VIDEO.value,
|
188 |
+
slt.SignFormatCodes.LANDMARKS.value,
|
189 |
+
],
|
190 |
+
value=slt.SignFormatCodes.VIDEO.value,
|
191 |
+
label="Output Format",
|
192 |
+
)
|
193 |
# todo: sign format: video/landmarks (tabs?)
|
194 |
|
195 |
+
with gradio.Column(): # Outputs
|
196 |
gradio.Markdown("## Output Sign Language")
|
197 |
output_video = gradio.Video(
|
198 |
format="mp4",
|
|
|
202 |
include_audio=False,
|
203 |
)
|
204 |
|
205 |
+
with gradio.Row(): # Translate Button
|
206 |
translate_button = gradio.Button("Translate", variant="primary")
|
207 |
translate_button.click(
|
208 |
translate,
|
209 |
+
inputs=[
|
210 |
+
source_textbox,
|
211 |
+
text_lang_dropdown,
|
212 |
+
sign_lang_dropdown,
|
213 |
+
output_format_dropdown,
|
214 |
+
],
|
215 |
outputs=[output_video],
|
216 |
api_name="translate",
|
217 |
)
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
sign-language-translator
|
2 |
opencv-python
|
|
|
1 |
+
sign-language-translator==0.8.*
|
2 |
opencv-python
|