Files changed (1) hide show
  1. app.py +0 -49
app.py DELETED
@@ -1,49 +0,0 @@
1
- import gradio as gr
2
- from transformers import MarianMTModel, MarianTokenizer
3
-
4
- def translate(text, target_language):
5
- language_codes = {
6
- "Spanish": "es",
7
- "French (European)": "fr",
8
- "French (Canadian)": "fr",
9
- "Italian": "it",
10
- "Ukrainian": "uk",
11
- "Portuguese (Brazilian)": "pt_BR",
12
- "Portuguese (European)": "pt",
13
- "Russian": "ru",
14
- "Chinese": "zh",
15
- "Dutch": "nl",
16
- "German": "de",
17
- "Arabic": "ar",
18
- "Hebrew": "he",
19
- "Greek": "el"
20
- }
21
- target_language_code = language_codes[target_language]
22
- model_name = f'helsinki-nlp/opus-mt-en-{target_language_code}'
23
- tokenizer = MarianTokenizer.from_pretrained(model_name)
24
- model = MarianMTModel.from_pretrained(model_name)
25
- inputs = tokenizer(text, return_tensors="pt")
26
- outputs = model.generate(**inputs)
27
- translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
28
- return translation
29
-
30
- language_options = [
31
- "Spanish", "French (European)", "French (Canadian)", "Italian", "Ukrainian",
32
- "Portuguese (Brazilian)", "Portuguese (European)", "Russian", "Chinese",
33
- "Dutch", "German", "Arabic", "Hebrew", "Greek"
34
- ]
35
-
36
- iface = gr.Interface(
37
- fn=translate,
38
- inputs=[
39
- gr.inputs.Textbox(lines=5, label="Enter text to translate:"),
40
- gr.inputs.Dropdown(choices=language_options, label="Target Language"),
41
- ],
42
- outputs=gr.outputs.Textbox(label="Translated Text"),
43
- )
44
-
45
- iface.launch()
46
-
47
-
48
-
49
-