Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,34 +4,37 @@ from transformers import pipeline
|
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
# ================================
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# ================================
|
| 9 |
@st.cache_resource
|
| 10 |
def load_translation_pipelines():
|
| 11 |
"""
|
| 12 |
Load and cache translation pipelines to avoid reloading on every interaction.
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return {'enja': enja, 'jaen': jaen, 'zhja': zhja}
|
| 19 |
-
except Exception as e:
|
| 20 |
-
st.error(f"Error loading translation models: {e}")
|
| 21 |
-
return {}
|
| 22 |
|
| 23 |
# Load the translation models
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# ================================
|
| 27 |
# Streamlit Application Layout
|
| 28 |
# ================================
|
| 29 |
-
st.set_page_config(
|
| 30 |
-
page_title="Multi-Language Translator",
|
| 31 |
-
layout="centered",
|
| 32 |
-
initial_sidebar_state="auto",
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
st.title("π Multi-Language Translator")
|
| 36 |
|
| 37 |
# Initialize session state for CSV creation flag
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
# ================================
|
| 7 |
+
# Streamlit Page Configuration
|
| 8 |
+
# ================================
|
| 9 |
+
st.set_page_config(
|
| 10 |
+
page_title="π Multi-Language Translator",
|
| 11 |
+
layout="centered",
|
| 12 |
+
initial_sidebar_state="auto",
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# ================================
|
| 16 |
+
# Cache the Translation Pipelines
|
| 17 |
# ================================
|
| 18 |
@st.cache_resource
|
| 19 |
def load_translation_pipelines():
|
| 20 |
"""
|
| 21 |
Load and cache translation pipelines to avoid reloading on every interaction.
|
| 22 |
"""
|
| 23 |
+
enja = pipeline("translation", model="staka/fugumt-en-ja")
|
| 24 |
+
jaen = pipeline("translation", model="staka/fugumt-ja-en")
|
| 25 |
+
zhja = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-zh-ja")
|
| 26 |
+
return {'enja': enja, 'jaen': jaen, 'zhja': zhja}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Load the translation models
|
| 29 |
+
try:
|
| 30 |
+
session_models = load_translation_pipelines()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
st.error(f"Error loading translation models: {e}")
|
| 33 |
+
session_models = {}
|
| 34 |
|
| 35 |
# ================================
|
| 36 |
# Streamlit Application Layout
|
| 37 |
# ================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
st.title("π Multi-Language Translator")
|
| 39 |
|
| 40 |
# Initialize session state for CSV creation flag
|