TiberiuCristianLeon commited on
Commit
167f186
·
verified ·
1 Parent(s): 0f80043

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -1,4 +1,26 @@
1
  import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import T5ForTranslation, T5Tokenizer
3
 
4
+ # Load the pre-trained model and tokenizer
5
+ model = T5ForTranslation.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
6
+ tokenizer = T5Tokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
7
+
8
+ # Create the app layout
9
+ st.title("Text Translation App")
10
+ text_input = st.text_input("Enter text to translate:")
11
+ submit_button = st.button("Translate")
12
+ translated_text = st.text("")
13
+
14
+ # Handle the submit button click
15
+ if submit_button:
16
+ # Encode the input text
17
+ encoded = tokenizer(text_input, return_tensors="pt")
18
+
19
+ # Perform translation
20
+ translated = model.generate(**encoded)
21
+
22
+ # Decode the translated text
23
+ translated_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
24
+
25
+ # Display the translated text
26
+ st.write("Translated Text:", translated_text[0])