ChatwithPDF / app.py
sreedeepEK's picture
Update app.py
b49c640 verified
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)