Spaces:
Sleeping
Sleeping
File size: 935 Bytes
8d9f984 a133ab7 6b2374b 8d9f984 a2ac978 a133ab7 a51fa5b a2ac978 a133ab7 8d9f984 a133ab7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# prompt: write a streamlit app that converts english text into french text when translate button is pressed. The title of page should be "Translate to French"."
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
import streamlit as st
st.title("Translate to French")
input_text = st.text_input("Enter text to translate")
if st.button("Translate"):
# Load the pre-trained model and tokenizer
model_name = "facebook/m2m100_418M"
model = M2M100ForConditionalGeneration.from_pretrained(model_name)
tokenizer = M2M100Tokenizer.from_pretrained(model_name)
# Tokenize input text
input_ids = tokenizer.encode(input_text, return_tensors="pt")
# Generate translation
translated_ids = model.generate(input_ids, target_language="fr")
# Decode and display the translated text
translation = tokenizer.decode(translated_ids[0], skip_special_tokens=True)
st.write(translation)
|