Spaces:
Runtime error
Runtime error
Update pages/resumo.py
Browse files- pages/resumo.py +37 -0
pages/resumo.py
CHANGED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from langchain.llms import HuggingFaceHub
|
3 |
+
from transformers import T5Tokenizer
|
4 |
+
from transformers import T5Model, T5ForConditionalGeneration
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
#Function to return the response
|
9 |
+
def load_answer(question):
|
10 |
+
token_name = 'unicamp-dl/ptt5-base-portuguese-vocab'
|
11 |
+
model_name = 'phpaiola/ptt5-base-summ-xlsum'
|
12 |
+
tokenizer = T5Tokenizer.from_pretrained(token_name )
|
13 |
+
model_pt = T5ForConditionalGeneration.from_pretrained(model_name)
|
14 |
+
inputs = tokenizer.encode(question, max_length=512, truncation=True, return_tensors='pt')
|
15 |
+
summary_ids = model_pt.generate(inputs, max_length=256, min_length=32, num_beams=5, no_repeat_ngram_size=3, early_stopping=True)
|
16 |
+
summary = tokenizer.decode(summary_ids[0])
|
17 |
+
return summary
|
18 |
+
|
19 |
+
#App UI starts here
|
20 |
+
st.image("https://www.viajenaviagem.com/wp-content/uploads/2020/02/belo-horizonte-pampulha.jpg.webp", caption='Autoria de Thiago Lanza. Todos os direitos reservados')
|
21 |
+
st.header("Resumo de frases")
|
22 |
+
st.subheader("Digite uma frase para que seja resumida")
|
23 |
+
|
24 |
+
#Gets the user input
|
25 |
+
def get_text():
|
26 |
+
input_text = st.text_input("Sua frase em português: ", key="input")
|
27 |
+
return input_text
|
28 |
+
|
29 |
+
user_input=get_text()
|
30 |
+
response = load_answer(user_input)
|
31 |
+
|
32 |
+
submit = st.button('Resumir')
|
33 |
+
|
34 |
+
if submit:
|
35 |
+
|
36 |
+
st.subheader("Resumo:")
|
37 |
+
st.write(response)
|