seyoungsong commited on
Commit
5b36141
1 Parent(s): a2b29a7
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,7 +1,12 @@
1
  from pathlib import Path
2
 
3
  import gradio as gr
4
- from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
 
 
 
 
 
5
 
6
  lang_to_code = {
7
  "Akrikaans": "af",
@@ -135,14 +140,11 @@ lang_names = list(lang_to_code.keys())
135
  cache_dir = Path("./cache_dir").resolve()
136
  cache_dir.mkdir(exist_ok=True, parents=True)
137
  print(f"cache_dir: {cache_dir}")
138
- tokenizer: M2M100Tokenizer = M2M100Tokenizer.from_pretrained(
139
- pretrained_model_name_or_path="seyoungsong/flores101_mm100_175M",
140
- cache_dir=str(cache_dir),
141
- )
142
- model = M2M100ForConditionalGeneration.from_pretrained(
143
- pretrained_model_name_or_path="seyoungsong/flores101_mm100_175M",
144
- cache_dir=str(cache_dir),
145
  )
 
 
146
 
147
  # fix tokenizer
148
  tokenizer.lang_token_to_id = {
 
1
  from pathlib import Path
2
 
3
  import gradio as gr
4
+ from transformers import (
5
+ M2M100ForConditionalGeneration,
6
+ M2M100Tokenizer,
7
+ TranslationPipeline,
8
+ pipeline,
9
+ )
10
 
11
  lang_to_code = {
12
  "Akrikaans": "af",
 
140
  cache_dir = Path("./cache_dir").resolve()
141
  cache_dir.mkdir(exist_ok=True, parents=True)
142
  print(f"cache_dir: {cache_dir}")
143
+ pipe: TranslationPipeline = pipeline(
144
+ task="translation", model="seyoungsong/flores101_mm100_175M"
 
 
 
 
 
145
  )
146
+ tokenizer: M2M100Tokenizer = pipe.tokenizer
147
+ model: M2M100ForConditionalGeneration = pipe.model
148
 
149
  # fix tokenizer
150
  tokenizer.lang_token_to_id = {