AIROBOHUB commited on
Commit
8a637b3
·
verified ·
1 Parent(s): b6e78a7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ import json
4
+
5
+ # Use a pipeline as a high-level helper
6
+ from transformers import pipeline
7
+
8
+ model_path="../Models/models--facebook--nllb-200-distilled-600M/snapshots/f8d333a098d19b4fd9a8b18f94170487ad3f821d"
9
+
10
+ text_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", torch_dtype=torch.bfloat16)
11
+
12
+ # text_translator = pipeline("translation", model=model_path,
13
+ # torch_dtype=torch.bfloat16)
14
+ # translation = text_translator()
15
+ def Translation_Text(text, destination_language):
16
+ dest_code= Get_flores_code_from_language(destination_language)
17
+ translation = text_translator(text,
18
+ src_lang="eng_Latn",
19
+ tgt_lang=dest_code,
20
+ max_length=500)
21
+ return translation[0]["translation_text"]
22
+
23
+ # Load the JSON data from the file
24
+ # with open('../Files/language.json', 'r') as file:
25
+ # language_data = json.load(file)
26
+
27
+ with open('language.json', 'r') as file:
28
+ language_data = json.load(file)
29
+
30
+ # Find and return the corresponding FLORES-200 code
31
+ def Get_flores_code_from_language(language):
32
+ for entry in language_data:
33
+ if entry['Language'].lower() == language.lower():
34
+ return entry['FLORES-200 code']
35
+ # If the language is not found, return None or an appropriate message
36
+ return None
37
+
38
+ gr.close_all()
39
+ # 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")
40
+
41
+ demo=gr.Interface(fn=Translation_Text,
42
+ 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")],
43
+ outputs=[gr.Textbox(label="Translated Text",lines=8)],
44
+ title="AI ROBO HUB Consulting Services Pvt. Ltd.",
45
+ 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")
46
+ demo.launch()