TRANSLATION_BOT / app.py
YasaswiniCh's picture
Update app.py
6aa98a8 verified
raw
history blame
989 Bytes
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load your trained model and tokenizer from Hugging Face
model_name = "ai4bharat/IndicTrans"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
# Streamlit UI
st.title("Colloquial Language Translator")
st.write("Enter English text to translate into the colloquial language of your choice.")
# User input
input_text = st.text_input("Enter English text:")
# When the button is clicked
if st.button("Translate"):
if input_text:
# Tokenize and generate output
inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)
outputs = model.generate(**inputs)
translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Display the result
st.success(f"Translation: {translation}")
else:
st.warning("Please enter some text to translate.")