ranjangoel/GPT-PDF
5
1import gradio as gr2 3from gpt_reader.pdf_reader import PaperReader4from gpt_reader.prompt import BASE_POINTS5 6 7class GUI:8 def __init__(self):9 self.api_key = ""10 self.session = ""11 12 def analyse(self, api_key, pdf_file):13 print(pdf_file)14 self.session = PaperReader(api_key, points_to_focus=BASE_POINTS)15 return self.session.read_pdf_and_summarize(pdf_file)16 17 def ask_question(self, question):18 if self.session == "":19 return "Please upload PDF file first!"20 return self.session.question(question)21 22 23with gr.Blocks() as demo:24 gr.Markdown(25 """26 # CHATGPT-PAPER-READER27 """)28 29 with gr.Tab("Upload PDF File"):30 pdf_input = gr.File(label="PDF File")31 api_input = gr.Textbox(label="OpenAI API Key")32 result = gr.Textbox(label="PDF Summary")33 upload_button = gr.Button("Start Analyse")34 with gr.Tab("Ask question about your PDF"):35 question_input = gr.Textbox(label="Your Question", placeholder="Authors of this paper?")36 answer = gr.Textbox(label="Answer")37 ask_button = gr.Button("Ask")38 with gr.Accordion("About this project"):39 gr.Markdown(40 """## CHATGPT-PAPER-READER📝 41 This repository provides a simple interface that utilizes the gpt-3.5-turbo 42 model to read academic papers in PDF format locally. You can use it to help you summarize papers, 43 create presentation slides, or simply fulfill tasks assigned by your supervisor.\n 44 [Github](https://github.com/talkingwallace/ChatGPT-Paper-Reader)""")45 46 app = GUI()47 upload_button.click(fn=app.analyse, inputs=[api_input, pdf_input], outputs=result)48 ask_button.click(app.ask_question, inputs=question_input, outputs=answer)49 50# if __name__ == "__main__":51demo.title = "GPT3.5 PDF Reader"52demo.launch() # add "share=True" to share CHATGPT-PAPER-READER app on Internet.53 