20 lines
637 B
Python
20 lines
637 B
Python
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']) |