File size: 1,598 Bytes
f87ab8f
6811e93
f87ab8f
 
 
6811e93
f87ab8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
058bf5c
c791d03
058bf5c
 
 
6811e93
 
058bf5c
 
 
 
 
 
 
 
 
 
6811e93
db4a040
058bf5c
 
 
db4a040
058bf5c
 
6811e93
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
import gradio as gr

from gpt_reader.pdf_reader import PaperReader
from gpt_reader.prompt import BASE_POINTS


class GUI:
    def __init__(self):
        self.api_key = ""
        self.session = ""

    def analyse(self, api_key, pdf_file):
        self.session = PaperReader(api_key, points_to_focus=BASE_POINTS)
        return self.session.read_pdf_and_summarize(pdf_file)

    def ask_question(self, question):
        if self.session == "":
            return "Please upload PDF file first!"
        return self.session.question(question)


with gr.Blocks() as demo:
    gr.Markdown(
        """
        # CHATGPT-PAPER-READER
        """)

    with gr.Tab("Upload PDF File"):
        pdf_input = gr.File(label="PDF File")
        api_input = gr.Textbox(label="OpenAI API Key")
        result = gr.Textbox(label="PDF Summary")
        upload_button = gr.Button("Start Analyse")
    with gr.Tab("Ask question about your PDF"):
        question_input = gr.Textbox(label="Your Question", placeholder="Authors of this paper?")
        answer = gr.Textbox(label="Answer")
        ask_button = gr.Button("Ask")
    with gr.Accordion("About this project"):
        gr.Markdown(
            """Simply upload your document and let our model read it within seconds!""")

    app = GUI()
    upload_button.click(fn=app.analyse, inputs=[api_input, pdf_input], outputs=result)
    ask_button.click(app.ask_question, inputs=question_input, outputs=answer)

if __name__ == "__main__":
    demo.title = "CHATGPT-PAPER-READER"
    demo.launch()  # add "share=True" to share CHATGPT-PAPER-READER app on Internet.