File size: 989 Bytes
9ad74d6
 
 
 
6aa98a8
9ad74d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.")