DDDSSS commited on
Commit
a25118a
1 Parent(s): b52df01

Upload demo.py

Browse files
Files changed (1) hide show
  1. demo.py +12 -0
demo.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
2
+
3
+ mode_name = 'DDDSSS/translation_en-zh'
4
+ device = 'cpu'
5
+ model = AutoModelForSeq2SeqLM.from_pretrained(mode_name)
6
+ # Model was saved using *save_pretrained('./test/saved_model/')* (for example purposes, not runnable).
7
+ tokenizer = AutoTokenizer.from_pretrained(mode_name)
8
+ translation = pipeline("translation_en_to_zh", model=model, tokenizer=tokenizer,
9
+ torch_dtype="float", device_map=True,device=device)
10
+ x=["If nothing is detected and there is a config.json file, it’s assumed the library is transformers.","By looking into the presence of files such as *.nemo or *saved_model.pb*, the Hub can determine if a model is from NeMo or Keras."]
11
+ re = translation(x, max_length=512)
12
+ print('翻译为:' ,re)