ShamilF's picture
Update app.py
cffbcc2
raw
history blame contribute delete
893 Bytes
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Initialize tokenizer and model
model_name = "your_hugging_face_model_name_or_url"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
def translate(text):
# Tokenize the text
input_ids = tokenizer.batch_encode_plus([text], return_tensors="pt")["input_ids"]
# Generate the translation
outputs = model.generate(input_ids, max_length=100)
# Decode the translation
translation = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
return translation
def main():
# Get the user's input
text = st.text_input("Enter a Russian text to translate:")
# Translate the text
translation = translate(text)
# Display the translation
st.text(translation)
if __name__ == "__main__":
main()