File size: 1,075 Bytes
2e4da92
 
 
66f7a3b
2e4da92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import torch

# Optionally display the torch version for verification
st.sidebar.write(f'PyTorch Version: {torch.__version__}')

# Load the model and tokenizer for Georgian to English translation
model_name = "Helsinki-NLP/opus-mt-ka-en"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# UI Title
st.title("Georgian to English Translator")

# UI for input text
text = st.text_area("Enter Georgian text:", height=150)

if st.button('Translate'):
    if text:
        # Prepare the text for translation
        inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
        # Translate the text
        translated = model.generate(**inputs)
        # Decode the translated text
        translation = tokenizer.decode(translated[0], skip_special_tokens=True)
        # Display the translation
        st.write(translation)
    else:
        st.write("Please enter some text to translate.")