Omnibus commited on
Commit
82b38e9
β€’
1 Parent(s): ac6d7f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -13,7 +13,7 @@ tokenizer = M2M100Tokenizer.from_pretrained("facebook/m2m100_1.2B")
13
  model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_1.2B").to(device)
14
  model.eval()
15
 
16
- l1="Afrikaans"
17
  class Language:
18
  def __init__(self, name, code):
19
  self.name = name
@@ -141,21 +141,9 @@ def trans_page(input,trg):
141
  translated_text=input
142
  pass
143
 
 
144
 
145
- if trg_lang != src_lang:
146
- new_lang = []
147
- tokenizer.src_lang = src_lang
148
- for langs in lang_id:
149
- with torch.no_grad():
150
- encoded_input = tokenizer(langs.name, return_tensors="pt").to(device)
151
- generated_tokens = model.generate(**encoded_input, forced_bos_token_id=tokenizer.get_lang_id(trg_lang))
152
- trans_langs = tokenizer.batch_decode(generated_tokens, skip_special_tokens=False)[0]
153
- new_lang.append(trans_langs)
154
- else:
155
- new_lang=lang_id
156
- pass
157
-
158
- return translated_text,gr.Dropdown.update(choices=[l.name for l in new_lang]),gr.Dropdown.update(choices=[l.name for l in new_lang])
159
 
160
  def trans_to(input,src,trg):
161
  for lang in lang_id:
@@ -208,7 +196,7 @@ with gr.Blocks() as transbot:
208
  message = gr.Textbox(label="Prompt",placeholder="Enter Prompt",lines=4)
209
  translated = gr.Textbox(label="Translated",lines=4,interactive=False)
210
  gr.Column()
211
- t_submit.click(trans_page,[md,t_space],[md,lang_from,lang_to])
212
 
213
  submit.click(trans_to, inputs=[message,lang_from,lang_to], outputs=[translated])
214
  transbot.queue(concurrency_count=20)
 
13
  model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_1.2B").to(device)
14
  model.eval()
15
 
16
+
17
  class Language:
18
  def __init__(self, name, code):
19
  self.name = name
 
141
  translated_text=input
142
  pass
143
 
144
+
145
 
146
+ return translated_text
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  def trans_to(input,src,trg):
149
  for lang in lang_id:
 
196
  message = gr.Textbox(label="Prompt",placeholder="Enter Prompt",lines=4)
197
  translated = gr.Textbox(label="Translated",lines=4,interactive=False)
198
  gr.Column()
199
+ t_submit.click(trans_page,[md,t_space],[md])
200
 
201
  submit.click(trans_to, inputs=[message,lang_from,lang_to], outputs=[translated])
202
  transbot.queue(concurrency_count=20)