import gradio import sign_language_translator as slt model = slt.models.ConcatenativeSynthesis("ur", "pk-sl", "video") def text_to_video( text: str, text_language: str, sign_language: str, output_path: str = "output.mp4", codec="h264", ): model.text_language = text_language model.sign_language = sign_language video = model.translate(text) video.save(output_path, overwrite=True, codec=codec) # ToDo: video.watermark("Sign Language Translator\nAI Generated Video") def predict(text: str, text_language: str, sign_language: str): try: path = "./output.mp4" text_to_video(text, text_language, sign_language, output_path=path, codec="mp4v") return path except Exception as exc: return gradio.Error(f"Error during translation: {exc}") gradio_app = gradio.Interface( fn=predict, inputs=[ gradio.Textbox( lines=2, placeholder="Enter Text Here...", label="Spoken Language Sentence", ), gradio.Dropdown( choices=[code.value for code in slt.TextLanguageCodes], value=slt.TextLanguageCodes.URDU.value, label="Text Language", ), gradio.Dropdown( choices=[code.value for code in slt.SignLanguageCodes], value=slt.SignLanguageCodes.PAKISTAN_SIGN_LANGUAGE.value, label="Sign Language", ), ], # type: ignore outputs=gradio.Video( format="mp4", label="Synthesized Sign Language Video", autoplay=True, show_download_button=True, include_audio=False, ), title="Concatenative Synthesis: Rule Based Text to Sign Language Translator", description="Enter your text and select options from the dropdowns, then click Submit to generate a video.\n\n" "The text is preprocessed, tokenized and rearranged and then each token is mapped to a prerecorded video which are concatenated and returned.\n\n" "> 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", examples=[ ["یہ بہت اچھا ہے۔", "ur", "pakistan-sign-language"], ["یہ کام بہت آسان ہے۔", "ur", "pakistan-sign-language"], ["पाँच घंटे।", "hi", "pakistan-sign-language"], # ["आप कैसे हैं", "hi", "pakistan-sign-language"], ], allow_flagging="auto", ) if __name__ == "__main__": gradio_app.launch()