Spaces:
Runtime error
Runtime error
Add profiler
Browse files
app.py
CHANGED
@@ -2,56 +2,61 @@ import streamlit as st
|
|
2 |
from extractor import extract, FewDocumentsError
|
3 |
from summarizer import summarize
|
4 |
import time
|
|
|
5 |
|
6 |
# TODO: translation
|
7 |
|
8 |
-
|
9 |
-
st.subheader("Lucas Antunes e Matheus Vieira")
|
10 |
-
|
11 |
-
st.subheader("Digite o t贸pico sobre o qual voc锚 deseja gerar um resumo")
|
12 |
-
query = st.text_input('Digite o t贸pico em ingl锚s') #text is stored in this variable
|
13 |
-
|
14 |
-
if 'few_documents' not in st.session_state:
|
15 |
-
st.session_state['few_documents'] = False
|
16 |
-
few_documents = False
|
17 |
-
else:
|
18 |
-
few_documents = st.session_state['few_documents']
|
19 |
-
|
20 |
-
button1 = st.button('Gerar resumo')
|
21 |
-
|
22 |
-
if button1:
|
23 |
-
start_time = time.time()
|
24 |
-
try:
|
25 |
-
with st.spinner('Extraindo textos relevantes...'):
|
26 |
-
text = extract(query)
|
27 |
-
except FewDocumentsError as e:
|
28 |
-
few_documents = True
|
29 |
-
st.session_state['few_documents'] = True
|
30 |
-
st.session_state['documents'] = e.documents
|
31 |
-
st.session_state['msg'] = e.msg
|
32 |
-
else:
|
33 |
-
|
34 |
-
st.info(f'(Extraction) Elapsed time: {time.time() - start_time:.2f}s')
|
35 |
-
with st.spinner('Gerando resumo...'):
|
36 |
-
summary = summarize(text)
|
37 |
-
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
38 |
-
|
39 |
-
st.markdown(f'Seu resumo para "{query}":\n\n> {summary}')
|
40 |
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
st.
|
44 |
-
if st.button('Prosseguir'):
|
45 |
-
start_time = time.time()
|
46 |
-
with st.spinner('Extraindo textos relevantes...'):
|
47 |
-
text = extract(query, extracted_documents=st.session_state['documents'])
|
48 |
-
st.info(f'(Extraction) Elapsed time: {time.time() - start_time:.2f}s')
|
49 |
-
with st.spinner('Gerando resumo...'):
|
50 |
-
summary = summarize(text)
|
51 |
-
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
52 |
-
|
53 |
-
st.markdown(f'Seu resumo para "{query}":\n\n> {summary}')
|
54 |
|
|
|
55 |
st.session_state['few_documents'] = False
|
56 |
few_documents = False
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from extractor import extract, FewDocumentsError
|
3 |
from summarizer import summarize
|
4 |
import time
|
5 |
+
import cProfile
|
6 |
|
7 |
# TODO: translation
|
8 |
|
9 |
+
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
st.title("Trabalho de Formatura - Construindo textos para a internet")
|
12 |
+
st.subheader("Lucas Antunes e Matheus Vieira")
|
13 |
|
14 |
+
st.subheader("Digite o t贸pico sobre o qual voc锚 deseja gerar um resumo")
|
15 |
+
query = st.text_input('Digite o t贸pico em ingl锚s') #text is stored in this variable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
if 'few_documents' not in st.session_state:
|
18 |
st.session_state['few_documents'] = False
|
19 |
few_documents = False
|
20 |
+
else:
|
21 |
+
few_documents = st.session_state['few_documents']
|
22 |
+
|
23 |
+
button1 = st.button('Gerar resumo')
|
24 |
+
|
25 |
+
if button1:
|
26 |
+
start_time = time.time()
|
27 |
+
try:
|
28 |
+
with st.spinner('Extraindo textos relevantes...'):
|
29 |
+
text = extract(query)
|
30 |
+
except FewDocumentsError as e:
|
31 |
+
few_documents = True
|
32 |
+
st.session_state['few_documents'] = True
|
33 |
+
st.session_state['documents'] = e.documents
|
34 |
+
st.session_state['msg'] = e.msg
|
35 |
+
else:
|
36 |
+
|
37 |
+
st.info(f'(Extraction) Elapsed time: {time.time() - start_time:.2f}s')
|
38 |
+
with st.spinner('Gerando resumo...'):
|
39 |
+
summary = summarize(text)
|
40 |
+
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
41 |
+
|
42 |
+
st.markdown(f'Seu resumo para "{query}":\n\n> {summary}')
|
43 |
+
|
44 |
+
|
45 |
+
if few_documents:
|
46 |
+
st.warning(st.session_state['msg'])
|
47 |
+
if st.button('Prosseguir'):
|
48 |
+
start_time = time.time()
|
49 |
+
with st.spinner('Extraindo textos relevantes...'):
|
50 |
+
text = extract(query, extracted_documents=st.session_state['documents'])
|
51 |
+
st.info(f'(Extraction) Elapsed time: {time.time() - start_time:.2f}s')
|
52 |
+
with st.spinner('Gerando resumo...'):
|
53 |
+
summary = summarize(text)
|
54 |
+
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
55 |
+
|
56 |
+
st.markdown(f'Seu resumo para "{query}":\n\n> {summary}')
|
57 |
+
|
58 |
+
st.session_state['few_documents'] = False
|
59 |
+
few_documents = False
|
60 |
+
|
61 |
+
if __name__ == '__main__':
|
62 |
+
cProfile.run('main()', 'stats.txt')
|