Spaces:
Runtime error
Runtime error
Add translation
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from extractor import extract, FewDocumentsError
|
| 3 |
from summarizer import summarize
|
|
|
|
| 4 |
import time
|
| 5 |
import cProfile
|
| 6 |
from sentence_transformers import SentenceTransformer
|
|
@@ -23,16 +24,22 @@ def init():
|
|
| 23 |
|
| 24 |
return search_model, summ_model, tokenizer
|
| 25 |
|
| 26 |
-
# TODO: translation
|
| 27 |
-
|
| 28 |
def main():
|
| 29 |
search_model, summ_model, tokenizer = init()
|
| 30 |
|
| 31 |
-
st.title("
|
| 32 |
-
st.subheader("Lucas Antunes
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
if 'few_documents' not in st.session_state:
|
| 38 |
st.session_state['few_documents'] = False
|
|
@@ -40,10 +47,9 @@ def main():
|
|
| 40 |
else:
|
| 41 |
few_documents = st.session_state['few_documents']
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
if button1:
|
| 46 |
start_time = time.time()
|
|
|
|
| 47 |
try:
|
| 48 |
with st.spinner('Extraindo textos relevantes...'):
|
| 49 |
text = extract(query, search_model=search_model)
|
|
@@ -59,7 +65,10 @@ def main():
|
|
| 59 |
summary = summarize(text, summ_model, tokenizer)
|
| 60 |
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
if few_documents:
|
|
@@ -73,7 +82,10 @@ def main():
|
|
| 73 |
summary = summarize(text, summ_model, tokenizer)
|
| 74 |
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
st.session_state['few_documents'] = False
|
| 79 |
few_documents = False
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from extractor import extract, FewDocumentsError
|
| 3 |
from summarizer import summarize
|
| 4 |
+
from translation import translate
|
| 5 |
import time
|
| 6 |
import cProfile
|
| 7 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 24 |
|
| 25 |
return search_model, summ_model, tokenizer
|
| 26 |
|
|
|
|
|
|
|
| 27 |
def main():
|
| 28 |
search_model, summ_model, tokenizer = init()
|
| 29 |
|
| 30 |
+
st.title("AutoSumm")
|
| 31 |
+
st.subheader("Lucas Antunes & Matheus Vieira")
|
| 32 |
+
|
| 33 |
+
portuguese = st.checkbox('Traduzir para o portugu锚s.')
|
| 34 |
|
| 35 |
+
if portuguese:
|
| 36 |
+
st.subheader("Digite o t贸pico sobre o qual voc锚 deseja gerar um resumo")
|
| 37 |
+
query_pt = st.text_input('Digite o t贸pico') #text is stored in this variable
|
| 38 |
+
button = st.button('Gerar resumo')
|
| 39 |
+
else:
|
| 40 |
+
st.subheader("Type the desired topic to generate the summary")
|
| 41 |
+
query = st.text_input('Type your topic') #text is stored in this variable
|
| 42 |
+
button = st.button('Generate summary')
|
| 43 |
|
| 44 |
if 'few_documents' not in st.session_state:
|
| 45 |
st.session_state['few_documents'] = False
|
|
|
|
| 47 |
else:
|
| 48 |
few_documents = st.session_state['few_documents']
|
| 49 |
|
| 50 |
+
if button:
|
|
|
|
|
|
|
| 51 |
start_time = time.time()
|
| 52 |
+
query = translate(query_pt, 'pt', 'en') if portuguese else query
|
| 53 |
try:
|
| 54 |
with st.spinner('Extraindo textos relevantes...'):
|
| 55 |
text = extract(query, search_model=search_model)
|
|
|
|
| 65 |
summary = summarize(text, summ_model, tokenizer)
|
| 66 |
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
| 67 |
|
| 68 |
+
if portuguese:
|
| 69 |
+
st.markdown(f'Seu resumo para "{query_pt}":\n\n> {translate(summary, "en", "pt")}')
|
| 70 |
+
else:
|
| 71 |
+
st.markdown(f'Your summary for "{query}":\n\n> {summary}')
|
| 72 |
|
| 73 |
|
| 74 |
if few_documents:
|
|
|
|
| 82 |
summary = summarize(text, summ_model, tokenizer)
|
| 83 |
st.info(f'(Total) Elapsed time: {time.time() - start_time:.2f}s')
|
| 84 |
|
| 85 |
+
if portuguese:
|
| 86 |
+
st.markdown(f'Seu resumo para "{query_pt}":\n\n> {translate(summary, "en", "pt")}')
|
| 87 |
+
else:
|
| 88 |
+
st.markdown(f'Your summary for "{query}":\n\n> {summary}')
|
| 89 |
|
| 90 |
st.session_state['few_documents'] = False
|
| 91 |
few_documents = False
|
translation/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .translation import translate
|
translation/__pycache__/__init__.cpython-39.pyc
ADDED
|
Binary file (183 Bytes). View file
|
|
|
translation/__pycache__/translate.cpython-39.pyc
ADDED
|
Binary file (643 Bytes). View file
|
|
|
translation/__pycache__/translation.cpython-39.pyc
ADDED
|
Binary file (647 Bytes). View file
|
|
|
translation/translation.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from deep_translator import GoogleTranslator
|
| 2 |
+
from easynmt import EasyNMT
|
| 3 |
+
|
| 4 |
+
def translate(text, source_language, target_language):
|
| 5 |
+
try:
|
| 6 |
+
print("Trying to use Google Translator...")
|
| 7 |
+
return GoogleTranslator(source = source_language, target = target_language).translate(text)
|
| 8 |
+
except:
|
| 9 |
+
print("Google Translator is not working... using M2M100")
|
| 10 |
+
translation_model = EasyNMT('m2m_100_418M')
|
| 11 |
+
return translation_model.translate(text, source_lang = source_language, target_lang = target_language)
|