Spaces:
Sleeping
Sleeping
Download app.py from AIROBOHUB/MultiLanguageTranslator: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/spaces/AIROBOHUB/MultiLanguageTranslator/resolve/main/app.py
- Command line
-
hf download hf://spaces/AIROBOHUB/MultiLanguageTranslator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AIROBOHUB/MultiLanguageTranslator/resolve/main/app.py
2.36 kB
| import torch | |
| import gradio as gr | |
| import json | |
| # Use a pipeline as a high-level helper | |
| from transformers import pipeline | |
| model_path="../Models/models--facebook--nllb-200-distilled-600M/snapshots/f8d333a098d19b4fd9a8b18f94170487ad3f821d" | |
| text_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", torch_dtype=torch.bfloat16) | |
| # text_translator = pipeline("translation", model=model_path, | |
| # torch_dtype=torch.bfloat16) | |
| # translation = text_translator() | |
| def Translation_Text(text, destination_language): | |
| dest_code= Get_flores_code_from_language(destination_language) | |
| translation = text_translator(text, | |
| src_lang="eng_Latn", | |
| tgt_lang=dest_code, | |
| max_length=500) | |
| return translation[0]["translation_text"] | |
| # Load the JSON data from the file | |
| # with open('../Files/language.json', 'r') as file: | |
| # language_data = json.load(file) | |
| with open('language.json', 'r') as file: | |
| language_data = json.load(file) | |
| # Find and return the corresponding FLORES-200 code | |
| def Get_flores_code_from_language(language): | |
| for entry in language_data: | |
| if entry['Language'].lower() == language.lower(): | |
| return entry['FLORES-200 code'] | |
| # If the language is not found, return None or an appropriate message | |
| return None | |
| gr.close_all() | |
| # demo=gr.Interface(fn=summary, inputs="text", outputs="text", title="AI ROBO HUB Consulting Services Pvt. Ltd.", description="This AI App is used to SUMMARIZE THE GIVEN TEXT - +91 7893688993 | chrao@airobohub.com") | |
| demo=gr.Interface(fn=Translation_Text, | |
| inputs=[gr.Textbox(label="Input Text to Translate (Max Length - 400)", lines=4),gr.Dropdown(["German","French","Japanese","Russian","Hindi","Sanskrit","Telugu","Kannada","Tamil","Marathi","Malayalam","Gujarati","Greek"],label="Select Destination Language")], | |
| outputs=[gr.Textbox(label="Translated Text",lines=8)], | |
| title="AI ROBO HUB Consulting Services Pvt. Ltd.", | |
| description="This AI App is MULTI LANGUAGE TRANSLATOR used to Translate English text into over 200 Languages (Currently supports 13 Languages) - It's POC, Accepts limited input text. For More Details: +91 7893688993 | chrao@airobohub.com") | |
| demo.launch() | |