Spaces:
Sleeping
Sleeping
File size: 1,149 Bytes
c21e277 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
from transformers import pipeline
# transformers パイプラインのインポート
fugu_translator_enja = pipeline('translation', model='staka/fugumt-en-ja')
fugu_translator_jaen = pipeline('translation', model='staka/fugumt-ja-en')
# デフォルトのモデル
current_model = 'enja'
# 関数: 翻訳を行う
def translate(model, text):
global current_model
# モデルが変更された場合、変更を反映
if model != current_model:
current_model = model
if current_model == 'enja':
return fugu_translator_enja(text)[0]['translation_text']
else:
return fugu_translator_jaen(text)[0]['translation_text']
# Streamlit アプリケーション
st.title("Fugu Translator")
# デフォルトの入力値
default_model = 'enja'
default_text = ''
# ユーザー入力の取得
model = st.selectbox("モデル", ['enja', 'jaen'], index=0, key='model')
text = st.text_area("入力テキスト", default_text)
# 翻訳ボタンが押されたときの処理
if st.button("翻訳する"):
result = translate(model, text)
st.write(f"翻訳結果: {result}")
|