Spaces:
Runtime error
Runtime error
Create traducao.py
Browse files- 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)
|