import gradio as gr import functions as functions # pre-defined questions questions = [ "What did the study investigate?", "Can you provide a summary of this paper?", "what are the methodologies used in this study?", "what are the data intervals used in this study? Give me the start dates and end dates?", "what are the main limitations of this study?", "what are the main shortcomings of this study?", "what are the main findings of the study?", "what are the main results of the study?", "what are the main contributions of this study?", "what is the conclusion of this paper?", "what are the input features used in this study?", "what is the dependent variable in this study?", ] title = 'PDF GPT Turbo' description = """ PDF GPT Turbo allows you to chat with your PDF files. It uses Google's Universal Sentence Encoder with Deep averaging network (DAN) to give hallucination free response by improving the embedding quality of OpenAI. It cites the page number in square brackets([Page No.]) and shows where the information is located, adding credibility to the responses.""" with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo: gr.Markdown(f'

{title}

') gr.Markdown(description) with gr.Row(): with gr.Group(): gr.Markdown(f'

Get your Open AI API key here

') with gr.Accordion("API Key"): openAI_key = gr.Textbox(label='Enter your OpenAI API key here', type='password') url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf )') gr.Markdown("

OR

") files = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'], file_count="multiple") question = gr.Textbox(label='Enter your question here') gr.Examples( [[q] for q in questions], inputs=[question], label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box, then press Enter!", ) model = gr.Radio([ 'gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k-0613', 'text-davinci-003', 'gpt-4', 'gpt-4-32k', 'gpt-4-1106-preview' ], label='Select Model', default='gpt-3.5-turbo') btn = gr.Button(value='Submit') btn.style(full_width=True) with gr.Group(): chatbot = gr.Chatbot(placeholder="Chat History", label="Chat History", lines=50, elem_id="chatbot") # Bind the click event of the button to the question_answer function btn.click( functions.question_answer, inputs=[chatbot, url, files, question, openAI_key, model], outputs=[chatbot], ) demo.launch(debug=True, show_error=True)