Spaces:
Sleeping
Sleeping
File size: 1,541 Bytes
a363bfe d22886a a363bfe 5809bcc 001f0c4 d22886a 72fb859 d22886a 72fb859 d22886a 72fb859 d22886a 1262fbb d22886a 72fb859 d22886a 7420847 72fb859 d22886a 001f0c4 d22886a 671af82 d22886a 2b8c4a9 |
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 |
import streamlit as st
from transformers import pipeline
x = st.slider('Select a value')
st.write(x, 'squared is', x * x)
# Title and Description
st.title("Translation Web App")
st.write("""
# Powered by Hugging Face and Streamlit
This app uses a pre-trained NLP model from Hugging Face to translate text from one language to another.
You can enter text and select the source and target languages for translation.
""")
# Cache model to improve performance
@st.cache_resource
def load_model():
print("Loading translation model...")
return pipeline("translation", model="Helsinki-NLP/opus-mt-en-ru") # Translation model: English to Russian
# Initialize Hugging Face Translation Pipeline
translator = load_model()
# Language selection (user chooses source and target language)
source_language = st.selectbox("Select Source Language", ["English", "French", "German", "Spanish", "Russian"])
target_language = st.selectbox("Select Target Language", ["English", "French", "German", "Spanish", "Russian"])
# Text input from the user
user_input = st.text_area("Enter text to translate:")
# Translate the input text
if user_input:
if source_language == target_language:
st.write("Source and target language are the same. Please choose different languages.")
else:
# Translate using Hugging Face model
translation = translator(user_input)
translated_text = translation[0]['translation_text']
st.write(f"### Translated Text ({target_language}):")
st.write(translated_text) |