thlanza commited on
Commit
ae57ed5
·
1 Parent(s): 0be4c02

Create traducao.py

Browse files
Files changed (1) hide show
  1. pages/traducao.py +23 -0
pages/traducao.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Function to return the response
2
+ def load_answer(question):
3
+ tokenizer = AutoTokenizer.from_pretrained("unicamp-dl/translation-pt-en-t5")
4
+ model = AutoModelForSeq2SeqLM.from_pretrained("unicamp-dl/translation-pt-en-t5")
5
+ pten_pipeline = pipeline('text2text-generation', model=model, tokenizer=tokenizer)
6
+ return pten_pipeline(question)[0]["generated_text"]
7
+
8
+ #Gets the user input
9
+ def get_text():
10
+ input_text = st.text_input("Sua frase em português: ", key="input")
11
+ return input_text
12
+
13
+ user_input=get_text()
14
+ response = load_answer(user_input)
15
+
16
+ submit = st.button('Traduzir para inglês')
17
+
18
+
19
+
20
+ if submit:
21
+
22
+ st.subheader("Answer:")
23
+ st.write(response)