Spaces:
Sleeping
Sleeping
Can Günen commited on
Commit ·
f1cc4d1
1
Parent(s): a84266b
added app fiel
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243# -*- coding: utf-8 -*-"""Created on Mon May 8 00:32:30 2023
@author: ahmet"""import pdfplumberimport gradio as grfrom transformers import AutoTokenizer, AutoModelForSeq2SeqLM
def respond(pdf_file): pdf_file_name = pdf_file.name all_text = '' with pdfplumber.open(pdf_file_name) as pdf: total_pages = len(pdf.pages) for idx, pdf_page in enumerate(pdf.pages): single_page_text = pdf_page.extract_text() all_text = all_text + '\n' + single_page_text print(idx/total_pages) if idx/total_pages >0.2: break tokenizer=AutoTokenizer.from_pretrained('Einmalumdiewelt/T5-Base_GNAD') model=AutoModelForSeq2SeqLM.from_pretrained('Einmalumdiewelt/T5-Base_GNAD', return_dict=True) inputs=tokenizer.encode("sumarize: " +all_text, return_tensors='pt', max_length=512, truncation=True) output = model.generate(inputs, min_length=70, max_length=80) summary=tokenizer.decode(output[0]) return summary
with gr.Blocks() as demo: title = """<p><h1 align="center" style="font-size: 36px;">Talk with your document</h1></p>""" gr.HTML(title) with gr.Row(): with gr.Column(): file_input = gr.File(label="PDF File", type="file") summarize = gr.Button("Summarize") text_output = gr.Textbox(label="Summarized text") summarize.click(fn=respond, inputs=file_input, outputs=text_output)
demo.launch(debug=True)app.pyAdded+43