Spaces:
Sleeping
Sleeping
File size: 1,416 Bytes
7615b30 e7075af 7615b30 e7075af 7615b30 |
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 |
import streamlit as st
from transformers import pipeline
# Set up the translator using a Hugging Face model
@st.cache_resource
def load_model(model_name):
return pipeline("translation", model=model_name)
# Title of the app
st.title("Language Translator App")
# Add input fields for text and target language selection
st.subheader("Enter the text you want to translate:")
input_text = st.text_area("Text to translate", height=150)
# Dropdown for language selection
language_options = {
"French": "Helsinki-NLP/opus-mt-en-fr",
"German": "Helsinki-NLP/opus-mt-en-de",
"Romanian": "Helsinki-NLP/opus-mt-en-ro",
"Spanish": "Helsinki-NLP/opus-mt-en-es",
"Italian": "Helsinki-NLP/opus-mt-en-it"
}
st.subheader("Select the target language:")
target_language = st.selectbox("Target Language", list(language_options.keys()))
# Translate button
if st.button("Translate"):
# Load the chosen model based on the selected language
selected_model = language_options[target_language]
translator = load_model(selected_model)
# Perform translation
if input_text:
translation = translator(input_text)
translated_text = translation[0]['translation_text']
# Display the translated text
st.subheader(f"Translated Text in {target_language}:")
st.write(translated_text)
else:
st.write("Please enter some text to translate.")
|