import os
import gradio as gr
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import Chroma
from langchain.chains import RetrievalQA
from langchain.llms import LlamaCpp
from langchain.document_loaders import PyPDFLoader
Initialize the LLM and embeddings
llm = LlamaCpp(model_path="path/to/llama-2-model") # Update with your model path
embeddings = HuggingFaceEmbeddings()
with gr.Tab("Upload PDF"):
pdf_upload = gr.File(label="Upload your PDF", file_types=[".pdf"])
pdf_list = gr.Dropdown(label="Select PDF", choices=uploaded_pdfs, multiselect=False)
pdf_upload.change(upload_and_list_pdfs, pdf_upload, pdf_list)
with gr.Tab("Chat"):
user_input = gr.Textbox(label="Ask a question about the selected PDF")
submit_button = gr.Button("Submit")
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
submit_button.click(query_chatbot, inputs=[user_input, pdf_list], outputs=chatbot_output)
Launch the app
if name == "main":
demo.launch()
gradio==3.0.0
langchain==0.0.1 # Use the latest version available
chromadb==0.3.21 # Ensure compatibility with your environment
PyPDF2==1.26.0 # For PDF processing
transformers==4.30.0 # For Hugging Face models and embeddings
torch==2.0.1 # Ensure you have PyTorch installed for Llama-2 model support