File size: 1,399 Bytes
544f171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b49c640
544f171
 
 
 
 
ee2a124
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
import gradio as gr
from dotenv import load_dotenv
from helper_function import get_conversation_chain, get_pdf_text, get_text_chunks, get_vectorstore

load_dotenv()

def chat_with_pdf(user_question, pdf_docs):
    if not pdf_docs:
        return "Please upload PDFs to process."
   
    # Process all uploaded files
    raw_text = get_pdf_text(pdf_docs)
    text_chunks = get_text_chunks(raw_text)
    vectorstore = get_vectorstore(text_chunks)
   
    # Create conversation chain
    conversation_chain = get_conversation_chain(vectorstore)
   
    # Handle user input using the appropriate method
    response = conversation_chain.run({'question': user_question})
    return response


# Define the Gradio interface
interface = gr.Interface(
    fn=chat_with_pdf,
    inputs=[
        gr.Textbox(label="Ask a question about your documents:"),
        gr.File(label="Upload your PDFs", type="binary", file_count="multiple")
    ],
    outputs="text",
    title="Chat with PDFs ",
    description="Your smart assistant for engaging with academic papers, research documents, and PDFs. Whether you need a quick summary, a deep dive into specific sections, or assistance with academic research, this tool helps you interact with your documents.",
    examples=[["What is the summary of this document?", None]]
)

# Launch the Gradio interface
if __name__ == '__main__':
    interface.launch(debug=True)