File size: 1,105 Bytes
0f80043
c1b6fa4
 
 
 
0f80043
c1b6fa4
 
167f186
 
 
 
 
 
 
 
 
 
c1b6fa4
 
167f186
 
c1b6fa4
 
167f186
 
c1b6fa4
167f186
 
 
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
import streamlit as st
from transformers import T5Tokenizer, T5ForConditionalGeneration
model_name = 't5-base'
tokenizer = T5Tokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)

# model = T5ForTranslation.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
# tokenizer = T5Tokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ro")

# Create the app layout
st.title("Text Translation App")
text_input = st.text_input("Enter text to translate:")
submit_button = st.button("Translate")
translated_text = st.text("")

# Handle the submit button click
if submit_button:
    # Encode the input text
    # encoded = tokenizer(text_input, return_tensors="pt")
    input_ids = tokenizer.encode(input_text, return_tensors='pt')

    # Perform translation
    output_ids = model.generate(input_ids)
    translated = tokenizer.decode(output_ids[0], skip_special_tokens=True)

    # Decode the translated text
    translated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)

    # Display the translated text
    st.write("Translated Text:", translated_text[0])