|
| 1 | +# Automated Quiz Generator from PDF Files |
| 2 | + |
| 3 | +This Python script automates the process of generating Multiple Choice Questions (MCQs) from the content of PDF files stored in a folder. The script extracts the text from the PDFs, generates unique questions with four answer options using a language model (LLM), and saves the quiz as a text file. This is useful for creating quizzes from educational or study material. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Automatic PDF Text Extraction**: Extracts text from all PDFs in a specified folder. |
| 8 | +- **MCQ Generation**: Generates unique multiple choice questions with 4 answer options and identifies the correct answer. |
| 9 | +- **Quiz Output**: Saves the quiz in a text format for easy review. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +The following Python packages are required to run the script: |
| 14 | +- PyPDF2 |
| 15 | +- langchain |
| 16 | +- langchain_groq |
| 17 | +- langchain_community |
| 18 | +- langchain_huggingface |
| 19 | +- faiss-cpu |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## How to Use the Automated Quiz Generator Script |
| 24 | + |
| 25 | +This guide will walk you through the steps to set up and run the Automated Quiz Generator, which converts PDF content into multiple-choice questions (MCQs). You will need to create an account with Groq to get an API key and set up your Python environment before running the script. |
| 26 | + |
| 27 | + |
| 28 | +### Step 1: Create a Groq Account and Get an API Key (100% free) |
| 29 | + |
| 30 | +1. **Visit Groq's Console**: |
| 31 | + Open your web browser and go to [Groq Console](https://console.groq.com/login). |
| 32 | + |
| 33 | +2. **Log In or Create an Account**: |
| 34 | + You can log in with your email, GitHub account, or create a new Groq account for free. |
| 35 | + |
| 36 | +3. **Generate an API Key**: |
| 37 | + - After logging in, navigate to the "API Keys" section in the Groq console. |
| 38 | + - Click the "Create API Key" button. |
| 39 | + - Enter a name for your API key (e.g., `quiz_key`). |
| 40 | + - **Important**: After you create the key, Groq will display it **only once**. Be sure to copy it correctly at this time. |
| 41 | + |
| 42 | +4. **Save the API Key**: |
| 43 | + You will need this key to run the quiz generator script. |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +### **Step 2: Add Your API Key to the Script** |
| 48 | + |
| 49 | +You have two options to use your API key. We recommend using the method 1 since, storing API keys directly in your code is risky because it exposes sensitive information, especially if you share or push your code to platforms like GitHub. Using a `.env` file is a safer approach because it keeps your keys private and separate from the code. It also prevents accidental exposure by ensuring the keys aren't included in version control systems like Git. This method enhances security and protects your application from unauthorized access. |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +#### **Option 1: Store the API Key in a `.env` File** |
| 54 | + |
| 55 | +1. Create a new file in the same directory as your script and name it `.env`. |
| 56 | +2. Open the `.env` file in a text editor. |
| 57 | +3. Add the following line to the `.env` file, replacing your_groq_api_key_here with your actual API key: |
| 58 | +``` |
| 59 | +GROQ_API_KEY=your_groq_api_key_here |
| 60 | +``` |
| 61 | +4. Save the `.env` file |
| 62 | + |
| 63 | +#### **Option 2: Paste the API Key Directly into the Script** |
| 64 | + |
| 65 | +1. Open the `quiz_generator.py` file in your code editor. |
| 66 | +2. Find the following line in the script (around line 38): |
| 67 | + ```python |
| 68 | + API_KEY = os.environ["GROQ_API_KEY"] |
| 69 | + ``` |
| 70 | +3. Replace the above line with your API key directly, like this: |
| 71 | + ```python |
| 72 | + API_KEY = "your_groq_api_key_here" |
| 73 | + ``` |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +### Step 3: Prepare the PDF files |
| 78 | +1. Create a folder (if not present) called Sources in the same directory as your Python script. |
| 79 | +2. Place all the PDF files that you want to generate quizzes from inside the Sources folder. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +### Step 4: Install the Dependencies |
| 84 | +1. Install all the required modules using this command: |
| 85 | +``` |
| 86 | +pip install -r requirements.txt |
| 87 | +``` |
| 88 | +
|
| 89 | +
|
| 90 | +--- |
| 91 | +
|
| 92 | +### Step 5: Run the Script |
| 93 | +1. To generate the quiz, open a terminal or command prompt in the folder where the script is located and run the following command: |
| 94 | +``` |
| 95 | +python quiz_generator.py |
| 96 | +``` |
| 97 | +This will extract the text from the PDFs, generate multiple-choice questions (MCQs) using the language model, and save the output in a text file named `generated_mcq_quiz.txt`. |
| 98 | +
|
0 commit comments