Spaces:
Runtime error
Runtime error
File size: 1,605 Bytes
c21e277 1ed3aa2 5c32f97 c21e277 750d299 c21e277 fa2f3cd c21e277 cd384ae 8ef7659 cd384ae 8ef7659 c21e277 8ef7659 c21e277 1303530 cd384ae 179bca5 1ed3aa2 |
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 40 41 42 43 44 45 46 47 48 |
import streamlit as st
import pandas as pd
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')
zhja_translator = pipeline("translation",model="Helsinki-NLP/opus-mt-tc-big-zh-ja")
# Streamlit アプリケーション
st.title("Multi-Language Translator")
# st.session_state で session-specific state を作成
if 'session_models' not in st.session_state:
st.session_state.session_models = {
'enja': fugu_translator_enja,
'jaen': fugu_translator_jaen,
'zhja': zhja_translator
}
# 初期化
if 'csv_created' not in st.session_state:
st.session_state.csv_created = False
# デフォルトの入力値
default_model = 'enja'
default_text = ''
# ユーザー入力の取得
model = st.selectbox("モデル", ['enja', 'jaen', 'zhja'], index=0, key='model')
text = st.text_area("入力テキスト", default_text)
# 翻訳ボタンが押されたときの処理
if st.button("翻訳する"):
# Perform translation
result = st.session_state.session_models[model](text)[0]['translation_text']
# Display the result
st.write(f"翻訳結果: {result}")
# Save the data to a CSV file
data = {'ID': [1], 'Original Text': [text], 'Result': [result]}
df = pd.DataFrame(data)
df.to_csv('translation_data.csv', mode='a', header=not st.session_state.csv_created, index=False)
# Update the CSV creation flag
st.session_state.csv_created = True
|