初始化项目,由ModelHub XC社区提供模型
Model: cyberagent/CAT-Translate-7b Source: Original Platform
This commit is contained in:
20
test.py
Normal file
20
test.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from transformers import pipeline
|
||||
|
||||
model_name = "CyberAgent/CAT-Translate-7b"
|
||||
chat_pipeline = pipeline("text-generation", model_name)
|
||||
|
||||
prompt = "Translate the following {src_lang} text into {tgt_lang}.\n\n {src_text}"
|
||||
|
||||
src_lang = "Japanese"
|
||||
tgt_lang = "English"
|
||||
src_text = "🐈はとてもかわいいの。おててがまるくてふわふわなの。"
|
||||
|
||||
user_input = [{"role": "user", "content": prompt.format(src_lang=src_lang, tgt_lang=tgt_lang, src_text=src_text)}]
|
||||
|
||||
response = chat_pipeline(user_input)
|
||||
|
||||
print("-" * 20)
|
||||
print("Source Text:")
|
||||
print(src_text)
|
||||
print("Translation:")
|
||||
print(response[0]['generated_text'][-1]['content'])
|
||||
Reference in New Issue
Block a user