import streamlit as st from transformers import pipeline # Available languages and their corresponding models available_languages = { "French": "Helsinki-NLP/opus-mt-en-fr", "German": "Helsinki-NLP/opus-mt-en-de", "Spanish": "Helsinki-NLP/opus-mt-en-es", "Chinese": "Helsinki-NLP/opus-mt-en-zh", "Japanese": "Helsinki-NLP/opus-mt-en-jap", "Russian": "Helsinki-NLP/opus-mt-en-ru", "Arabic": "Helsinki-NLP/opus-mt-en-ar", "Urdu": "Helsinki-NLP/opus-mt-en-ur", } # Streamlit app title st.title("Language Translator") # User input for text to translate text_to_translate = st.text_area("Enter text in English:", "") # Language selection target_language = st.selectbox("Select the target language:", list(available_languages.keys())) # Load the translation model based on the selected language translator = pipeline("translation", model=available_languages[target_language]) # Translate button if st.button("Translate"): if text_to_translate: # Perform the translation translation = translator(text_to_translate) # Display the translated text st.write(f"**Translated text in {target_language}:**") st.write(translation[0]['translation_text']) else: st.warning("Please enter some text to translate.") # Footer st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/).")