def do_summary(): fname = handle_uploaded() if not fname: st.write('Please upload a file!') nlp = Summarizer() nlp.from_file(fname) kws, _, sents, picg = nlp.info() with right: st.write("\nSUMMARY:") for sent in sents: st.write(sent) st.write("\nKEYWORDS:") # for w in kws: st.write(w) s = "; ".join(kws) st.write(s)
def summarize_one(pdf, trim, texts, sums, keys, lang): """ summarizer for one document """ if pdf[-4:].lower() != ".pdf": return None name = pdf[trim:-4] tname0 = texts + name tname = texts + name + ".txt" sname = sums + name + ".txt" kname = keys + name + ".txt" ensure_path(tname) try: print('START processing:', pdf) if not (pdf2txt(pdf, tname)): print('Unable to convert from PDF, skipping file!') return None clean_text_file(tname, lang=lang) nlp = Summarizer(lang=lang) nlp.from_file(tname0) kws, _, sents, _ = nlp.info() ktext = "\n".join(kws) ensure_path(kname) string2file(ktext, kname) stext = "\n".join(sents) ensure_path(sname) string2file(stext, sname) print('WRITTEN TO', sname, kname) text = "\n".join( ['FILE:', pdf, '\nSUMMARY:', stext, '\nKEYWORDS:', ktext, '\n']) print('DONE processing:', pdf) return text except IndexError: print('ERROR:', sys.exc_info()[0]) print('Processing failed on:', pdf) return None except ValueError: return None except RuntimeError: return None