Spaces:
Running
Running
basic text to video interface
Browse files- app.py +68 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
import sign_language_translator as slt
|
3 |
+
|
4 |
+
model = slt.models.ConcatenativeSynthesis("ur", "pk-sl", "video")
|
5 |
+
|
6 |
+
|
7 |
+
def text_to_video(
|
8 |
+
text: str, text_language: str, sign_language: str, output_path: str = "output.mp4"
|
9 |
+
):
|
10 |
+
model.text_language = text_language
|
11 |
+
model.sign_language = sign_language
|
12 |
+
|
13 |
+
video = model.translate(text)
|
14 |
+
video.save(output_path, overwrite=True)
|
15 |
+
|
16 |
+
# ToDo: video.watermark("Sign Language Translator\nAI Generated Video")
|
17 |
+
|
18 |
+
|
19 |
+
def predict(text: str, text_language: str, sign_language: str):
|
20 |
+
try:
|
21 |
+
path = "./output.mp4"
|
22 |
+
text_to_video(text, text_language, sign_language, output_path=path)
|
23 |
+
return path
|
24 |
+
except Exception as exc:
|
25 |
+
return gradio.Error(f"Error during translation: {exc}")
|
26 |
+
|
27 |
+
|
28 |
+
gradio_app = gradio.Interface(
|
29 |
+
fn=predict,
|
30 |
+
inputs=[
|
31 |
+
gradio.Textbox(
|
32 |
+
lines=2,
|
33 |
+
placeholder="Enter Text Here...",
|
34 |
+
label="Spoken Language Sentence",
|
35 |
+
),
|
36 |
+
gradio.Dropdown(
|
37 |
+
choices=[code.value for code in slt.TextLanguageCodes],
|
38 |
+
value=slt.TextLanguageCodes.URDU.value,
|
39 |
+
label="Text Language",
|
40 |
+
),
|
41 |
+
gradio.Dropdown(
|
42 |
+
choices=[code.value for code in slt.SignLanguageCodes],
|
43 |
+
value=slt.SignLanguageCodes.PAKISTAN_SIGN_LANGUAGE.value,
|
44 |
+
label="Sign Language",
|
45 |
+
),
|
46 |
+
], # type: ignore
|
47 |
+
outputs=gradio.Video(
|
48 |
+
format="mp4",
|
49 |
+
label="Synthesized Sign Language Video",
|
50 |
+
autoplay=True,
|
51 |
+
show_download_button=True,
|
52 |
+
include_audio=False,
|
53 |
+
),
|
54 |
+
title="Concatenative Synthesis: Rule Based Text to Sign Language Translator",
|
55 |
+
description="Enter your text and select options from the dropdowns, then click Submit to generate a video.\n\n"
|
56 |
+
"The text is preprocessed, tokenized and rearranged and then each token is mapped to a prerecorded video which are concatenated and returned.\n\n"
|
57 |
+
"> NOTE: This model only supports a fixed vocabulary. Check the `*-dictionary-mapping.json` on https://github.com/sign-language-translator/sign-language-datasets/tree/main/parallel_texts",
|
58 |
+
examples=[
|
59 |
+
["یہ بہت اچھا ہے۔", "ur", "pakistan-sign-language"],
|
60 |
+
["یہ کام بہت آسان ہے۔", "ur", "pakistan-sign-language"],
|
61 |
+
["पाँच घंटे।", "hi", "pakistan-sign-language"],
|
62 |
+
# ["आप कैसे हैं", "hi", "pakistan-sign-language"],
|
63 |
+
],
|
64 |
+
allow_flagging="auto",
|
65 |
+
)
|
66 |
+
|
67 |
+
if __name__ == "__main__":
|
68 |
+
gradio_app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
sign-language-translator
|