Hira99 commited on
Commit
e7075af
1 Parent(s): 21a1ae8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
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 (you can replace this with the model of your choice)
5
- @st.cache(allow_output_mutation=True)
6
- def load_model():
7
- return pipeline("translation_en_to_fr", model="Helsinki-NLP/opus-mt-en-fr")
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 = pipeline("translation", model=selected_model)
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
+