lodhrangpt commited on
Commit
21e4d46
·
verified ·
1 Parent(s): 12a1ffc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -19
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
3
 
4
  # Load the translation model and tokenizer from Hugging Face
5
- # Here, we use the "Helsinki-NLP" translation models
6
  model_name = "Helsinki-NLP/opus-mt-en-fr" # Example model for English to French
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
@@ -15,34 +14,23 @@ def translate_text(text, target_language):
15
  translation = translator(text)[0]['translation_text']
16
  return translation
17
 
18
- # Set up the Gradio interface
19
  languages = {
20
- "en": "English",
21
- "es": "Spanish",
22
  "fr": "French",
 
23
  "de": "German",
24
- "zh": "Chinese (Mandarin)",
25
- "ja": "Japanese",
26
- "ko": "Korean",
27
  "it": "Italian",
28
- "pt": "Portuguese",
29
- "ru": "Russian",
30
- "hi": "Hindi",
31
- "ar": "Arabic",
32
- "nl": "Dutch",
33
- "tr": "Turkish",
34
- "el": "Greek",
35
- "ur": "Urdu"
36
  }
37
 
38
-
39
  iface = gr.Interface(
40
  fn=translate_text,
41
  inputs=[
42
- gr.inputs.Textbox(label="Enter text to translate"),
43
- gr.inputs.Dropdown(list(languages.keys()), label="Target Language", type="value")
44
  ],
45
- outputs="text",
46
  live=True,
47
  title="Text Translator",
48
  description="Translate text into multiple languages using Hugging Face models."
 
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
3
 
4
  # Load the translation model and tokenizer from Hugging Face
 
5
  model_name = "Helsinki-NLP/opus-mt-en-fr" # Example model for English to French
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
 
14
  translation = translator(text)[0]['translation_text']
15
  return translation
16
 
17
+ # Define available languages
18
  languages = {
 
 
19
  "fr": "French",
20
+ "es": "Spanish",
21
  "de": "German",
 
 
 
22
  "it": "Italian",
23
+ "ru": "Russian"
 
 
 
 
 
 
 
24
  }
25
 
26
+ # Set up the Gradio interface
27
  iface = gr.Interface(
28
  fn=translate_text,
29
  inputs=[
30
+ gr.Textbox(label="Enter text to translate"),
31
+ gr.Dropdown(list(languages.keys()), label="Target Language", type="value")
32
  ],
33
+ outputs=gr.Textbox(label="Translation"),
34
  live=True,
35
  title="Text Translator",
36
  description="Translate text into multiple languages using Hugging Face models."