Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,29 +7,18 @@ fugu_translator_jaen = pipeline('translation', model='staka/fugumt-ja-en')
|
|
| 7 |
zhja_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-zh-ja")
|
| 8 |
jazh_translator = pipeline(model="larryvrh/mt5-translation-ja_zh")
|
| 9 |
|
| 10 |
-
# デフォルトのモデル
|
| 11 |
-
current_model = 'enja'
|
| 12 |
-
|
| 13 |
-
# 関数: 翻訳を行う
|
| 14 |
-
def translate(model, text):
|
| 15 |
-
global current_model
|
| 16 |
-
|
| 17 |
-
# モデルが変更された場合、変更を反映
|
| 18 |
-
if model != current_model:
|
| 19 |
-
current_model = model
|
| 20 |
-
|
| 21 |
-
if current_model == 'enja':
|
| 22 |
-
return fugu_translator_enja(text)[0]['translation_text']
|
| 23 |
-
elif current_model == 'jaen':
|
| 24 |
-
return fugu_translator_jaen(text)[0]['translation_text']
|
| 25 |
-
elif current_model == 'zhja':
|
| 26 |
-
return zhja_translator(text)[0]['translation_text']
|
| 27 |
-
elif current_model == 'jazh':
|
| 28 |
-
return jazh_translator(text)
|
| 29 |
-
|
| 30 |
# Streamlit アプリケーション
|
| 31 |
st.title("Multi-Language Translator")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# デフォルトの入力値
|
| 34 |
default_model = 'enja'
|
| 35 |
default_text = ''
|
|
@@ -40,5 +29,11 @@ text = st.text_area("入力テキスト", default_text)
|
|
| 40 |
|
| 41 |
# 翻訳ボタンが押されたときの処理
|
| 42 |
if st.button("翻訳する"):
|
| 43 |
-
result =
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
zhja_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-zh-ja")
|
| 8 |
jazh_translator = pipeline(model="larryvrh/mt5-translation-ja_zh")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Streamlit アプリケーション
|
| 11 |
st.title("Multi-Language Translator")
|
| 12 |
|
| 13 |
+
# st.session_state で session-specific state を作成
|
| 14 |
+
if 'session_models' not in st.session_state:
|
| 15 |
+
st.session_state.session_models = {
|
| 16 |
+
'enja': fugu_translator_enja,
|
| 17 |
+
'jaen': fugu_translator_jaen,
|
| 18 |
+
'zhja': zhja_translator,
|
| 19 |
+
'jazh': jazh_translator
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
# デフォルトの入力値
|
| 23 |
default_model = 'enja'
|
| 24 |
default_text = ''
|
|
|
|
| 29 |
|
| 30 |
# 翻訳ボタンが押されたときの処理
|
| 31 |
if st.button("翻訳する"):
|
| 32 |
+
result = st.session_state.session_models[model](text)[0]['translation_text']
|
| 33 |
+
|
| 34 |
+
# Outputをcollumまたはcontainerに格納
|
| 35 |
+
output_col, _ = st.columns(2)
|
| 36 |
+
output_col.write(f"翻訳結果: {result}")
|
| 37 |
+
|
| 38 |
+
# Experimental rerun without re-executing the entire app
|
| 39 |
+
st.experimental_rerun([output_col])
|