Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Set up the translator using a Hugging Face model
|
5 |
-
@st.
|
6 |
-
def load_model():
|
7 |
-
return pipeline("
|
8 |
-
|
9 |
-
# Load the model
|
10 |
-
translator = load_model()
|
11 |
|
12 |
# Title of the app
|
13 |
st.title("Language Translator App")
|
@@ -32,7 +29,7 @@ target_language = st.selectbox("Target Language", list(language_options.keys()))
|
|
32 |
if st.button("Translate"):
|
33 |
# Load the chosen model based on the selected language
|
34 |
selected_model = language_options[target_language]
|
35 |
-
translator =
|
36 |
|
37 |
# Perform translation
|
38 |
if input_text:
|
@@ -44,3 +41,4 @@ if st.button("Translate"):
|
|
44 |
st.write(translated_text)
|
45 |
else:
|
46 |
st.write("Please enter some text to translate.")
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Set up the translator using a Hugging Face model
|
5 |
+
@st.cache_resource
|
6 |
+
def load_model(model_name):
|
7 |
+
return pipeline("translation", model=model_name)
|
|
|
|
|
|
|
8 |
|
9 |
# Title of the app
|
10 |
st.title("Language Translator App")
|
|
|
29 |
if st.button("Translate"):
|
30 |
# Load the chosen model based on the selected language
|
31 |
selected_model = language_options[target_language]
|
32 |
+
translator = load_model(selected_model)
|
33 |
|
34 |
# Perform translation
|
35 |
if input_text:
|
|
|
41 |
st.write(translated_text)
|
42 |
else:
|
43 |
st.write("Please enter some text to translate.")
|
44 |
+
|