This Streamlit application allows users to upload a PDF document and ask questions about its content using an AI model. The application utilizes the Groq API and the LLaMA model from Hugging Face to provide answers based on the extracted text from the PDF.
- PDF Upload: Easily upload any PDF document.
- Text Extraction: Extract text from the uploaded PDF.
- Question Answering: Ask questions about the PDF content and get accurate answers.
- User-Friendly UI: Enhanced with Streamlit's components, sidebars, buttons, icons, and color contrasts.
To run this application locally, follow the steps below.
- Python 3.7 or higher
- Streamlit
- Groq API key
-
Clone the Repository:
git clone https://github.com/yourusername/pdf-query-app.git cd pdf-query-app
-
Install the Required Packages:
Install all the required Python libraries by running:
pip install -r requirements.txt
-
Get Groq API Key:
- Sign up or log in to Groq.
- Obtain your API key by navigating to your account settings and selecting API keys.
- Set your API key in the environment variables by running:
export GROQ_API_KEY=<your-api-key-here>
-
Run the Application:
Start the Streamlit app by running:
streamlit run app.py
Open the provided URL in your web browser to use the app.
- Upload a PDF: Click the "Upload a PDF file" button and select a PDF from your device.
- Extract Text: Once the PDF is uploaded, the text will be extracted and displayed in the text area.
- Ask a Question: Enter your query about the PDF content in the input box.
- Get Answer: Click the "Get Answer" button to generate a response based on your query.
- Model Name:
meta-llama/Llama-2-7b-hf
- Description: This model is optimized for natural language understanding and question-answering tasks.
- Link to Model: LLaMA-2 on Hugging Face
To use this model in your app:
from transformers import AutoTokenizer, LlamaForCausalLM
model = LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
To access this model:
- Visit the LLaMA-2 Model page on Hugging Face.
- If it's a gated model, request access and ensure you are logged into your Hugging Face account.
Below are the packages required for this application:
streamlit
groq
pdfplumber
torch
transformers
Try the demo of this app on Hugging Face Spaces to see it in action!
- Link to Hugging Face Space: Demo on Hugging Face
This project is licensed under the MIT License - see the LICENSE.md file for details.
Contributions are welcome! Please fork the repository and submit a pull request.
- Streamlit for providing an easy-to-use web application framework.
- Groq for their powerful API for language models.
- Hugging Face for hosting models and providing access to state-of-the-art NLP models.
Made with ❤️ by Ahmad Raza.