Spaces:
Running
Running
File size: 1,557 Bytes
3919e25 2e2a7b2 4ffb3fe a923971 3919e25 2d1281f a923971 d599b56 d02b2ab a923971 d846da3 2e2a7b2 a923971 e86a2c5 2e2a7b2 b7f89cc 2e2a7b2 1c5b68c fb04ca9 1e634f8 8f70505 502b110 d599b56 d846da3 9c7f619 563ca5d 1e634f8 ba73e05 d846da3 3919e25 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
import requests
from pypdf import PdfReader
def scrape(instring):
html_src=(f'''
<div style="text-align:center">
<h4>PDF Viewer</h4>
<iframe src="https://docs.google.com/viewer?url={instring}&embedded=true" frameborder="0" height="1200px" width="100%"></iframe>
</div>''')
return gr.HTML.update(f'''{html_src}''')
def scrape00(instring, page_num):
response = requests.get(instring, stream=True)
if response.status_code == 200:
with open("data.pdf", "wb") as f:
f.write(response.content)
else:
print(response.status_code)
#out = Path("./data.pdf")
#print (out)
reader = PdfReader("data.pdf")
number_of_pages = len(reader.pages)
page = reader.pages[int(page_num)-1]
text = page.extract_text()
print (text)
try:
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
sum_out = summarizer(text)
except Exception:
sum_out = "Error"
return text, sum_out
with gr.Blocks() as app:
gr.Markdown('''<h1>PDF Viewer''')
with gr.Row():
inp=gr.Textbox(label="PDF URL",scale=3)
pg_num=gr.Number(label="Page Number",value=1,precision=0,scale=1)
with gr.Row():
go_btn = gr.Button("Load PDF")
sum_btn = gr.Button("Summarize")
outp = gr.HTML()
with gr.Row():
text_out = gr.Textbox()
sum_out = gr.Textbox()
go_btn.click(scrape,inp,outp)
sum_btn.click(scrape00,[inp,pg_num],[text_out,sum_out])
app.queue(concurrency_count=10).launch() |