sethanimesh commited on
Commit
1e0bf7f
·
verified ·
1 Parent(s): 2152c7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -30
app.py CHANGED
@@ -1,11 +1,7 @@
1
- import os
2
- import torch
3
  import gradio as gr
4
- import time
5
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
6
  from flores200_codes import flores_codes
7
 
8
-
9
  def load_models():
10
  # build model and tokenizer
11
  model_name_dict = {'nllb-distilled-600M': 'facebook/nllb-200-distilled-600M',
@@ -25,8 +21,7 @@ def load_models():
25
 
26
  return model_dict
27
 
28
-
29
- def translation(source, target, text):
30
  if len(model_dict) == 2:
31
  model_name = 'nllb-distilled-600M'
32
 
@@ -51,35 +46,21 @@ def translation(source, target, text):
51
 
52
 
53
  if __name__ == '__main__':
54
- print('\tinit models')
55
-
56
- global model_dict
57
-
58
  model_dict = load_models()
59
-
60
- # define gradio demo
61
  lang_codes = list(flores_codes.keys())
62
- #inputs = [gr.Image.Radio(['nllb-distilled-600M', 'nllb-1.3B', 'nllb-distilled-1.3B'], label='NLLB Model'),
63
- Image = [gr.Image.Dropdown(lang_codes, default='English', label='Source'),
64
- gr.Image.Dropdown(lang_codes, default='Korean', label='Target'),
65
- gr.Image.Textbox(lines=5, label="Input text"),
66
- ]
67
 
68
- Label = gr.Label.JSON()
 
 
 
 
 
69
 
70
- title = "NLLB distilled 600M demo"
71
 
 
72
  demo_status = "Demo is running on CPU"
73
  description = f"Details: https://github.com/facebookresearch/fairseq/tree/nllb. {demo_status}"
74
- examples = [
75
- ['English', 'Korean', 'Hi. nice to meet you']
76
- ]
77
-
78
- gr.Interface(translation,
79
- Image,
80
- Label,
81
- title=title,
82
- description=description,
83
- ).launch()
84
-
85
 
 
 
 
 
1
  import gradio as gr
 
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
  from flores200_codes import flores_codes
4
 
 
5
  def load_models():
6
  # build model and tokenizer
7
  model_name_dict = {'nllb-distilled-600M': 'facebook/nllb-200-distilled-600M',
 
21
 
22
  return model_dict
23
 
24
+ def translation(source, target, text, model_name="nllb-distilled-600M"):
 
25
  if len(model_dict) == 2:
26
  model_name = 'nllb-distilled-600M'
27
 
 
46
 
47
 
48
  if __name__ == '__main__':
 
 
 
 
49
  model_dict = load_models()
50
+
 
51
  lang_codes = list(flores_codes.keys())
 
 
 
 
 
52
 
53
+ inputs = [
54
+ gr.components.Dropdown(lang_codes, default='English', label='Source'),
55
+ gr.components.Dropdown(lang_codes, default='Korean', label='Target'),
56
+ gr.components.Textbox(lines=5, label="Input text"),
57
+ gr.components.Dropdown(["nllb-distilled-600M"], default="nllb-distilled-600M", label="Model"),
58
+ ]
59
 
60
+ outputs = gr.components.JSON()
61
 
62
+ title = "NLLB distilled 600M demo"
63
  demo_status = "Demo is running on CPU"
64
  description = f"Details: https://github.com/facebookresearch/fairseq/tree/nllb. {demo_status}"
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ gr.Interface(translation, inputs, outputs, title=title, description=description).launch()