import streamlit as st from transformers import pipeline import torch print(torch.__version__) # Define the available models for translation models = { "Urdu": "Helsinki-NLP/opus-mt-en-ur", "Chinese": "Helsinki-NLP/opus-mt-en-zh", "Arabic": "Helsinki-NLP/opus-mt-en-ar", "French": "Helsinki-NLP/opus-mt-en-fr", "German": "Helsinki-NLP/opus-mt-en-de", "Spanish": "Helsinki-NLP/opus-mt-en-es", "Italian": "Helsinki-NLP/opus-mt-en-it", #"Japanese": "Helsinki-NLP/opus-mt-en-ja", "Russian": "Helsinki-NLP/opus-mt-en-ru", "Hindi": "Helsinki-NLP/opus-mt-en-hi", } # Streamlit UI setup st.title("Multilingual Translator App") st.write("Translate text from English to multiple languages.") # Target language selection target_language = st.selectbox("Select target language:", list(models.keys())) # Load the translation model model_name = models[target_language] translator = pipeline("translation", model=model_name) # Text input text_input = st.text_area("Enter English text to translate:") # Translate button if st.button("Translate"): if text_input: # Perform translation translated_text = translator(text_input)[0]['translation_text'] st.write(f"**Translated Text ({target_language}):** {translated_text}") else: st.write("Please enter some text to translate.") # Footer note st.write("Powered by Hugging Face Transformers and Streamlit.")