You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
3
+
This Python script automates the process of generating Multiple Choice Questions (MCQs) from the content of PDF files stored in a folder. It 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.
6
4
7
5
-**Automatic PDF Text Extraction**: Extracts text from all PDFs in a specified folder.
8
6
-**MCQ Generation**: Generates unique multiple choice questions with 4 answer options and identifies the correct answer.
9
7
-**Quiz Output**: Saves the quiz in a text format for easy review.
10
8
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
9
+
## Setup Instructions
24
10
25
11
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
12
27
-
28
13
### Step 1: Create a Groq Account and Get an API Key (100% free)
29
14
30
15
1.**Visit Groq's Console**:
@@ -44,59 +29,68 @@ This guide will walk you through the steps to set up and run the Automated Quiz
44
29
45
30
---
46
31
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.
32
+
### Step 2: Add Your API Key to the Script
50
33
34
+
You have two options to use your API key. We recommend using option 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.
51
35
52
-
53
-
#### **Option 1: Store the API Key in a `.env` File**
36
+
#### Option 1: Store the API Key in a `.env` File
54
37
55
38
1. Create a new file in the same directory as your script and name it `.env`.
56
39
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:
40
+
3. Add the following line to the `.env` file, replacing `your_groq_api_key_here` with your actual API key:
58
41
```
59
-
GROQ_API_KEY=your_groq_api_key_here
42
+
GROQ_API_KEY="your_groq_api_key_here"
60
43
```
61
-
4. Save the `.env` file
44
+
4. Save the `.env` file.
62
45
63
-
#### **Option 2: Paste the API Key Directly into the Script**
46
+
#### Option 2: Paste the API Key Directly into the Script
64
47
65
48
1. Open the `main.py` file in your code editor.
66
49
2. Find the following line in the script (around line 38):
67
-
```python
68
-
API_KEY= os.environ["GROQ_API_KEY"]
69
-
```
50
+
```python
51
+
API_KEY= os.environ["GROQ_API_KEY"]
52
+
```
70
53
3. Replace the above line with your API key directly, like this:
71
-
```python
72
-
API_KEY="your_groq_api_key_here"
73
-
```
54
+
```python
55
+
API_KEY="your_groq_api_key_here"
56
+
```
74
57
75
58
---
76
59
77
-
### Step 3: Prepare the PDF files
60
+
### Step 3: Prepare the PDF Files
61
+
78
62
1. Create a folder (if not present) called `Source` in the same directory as your Python script.
79
63
2. Place all the PDF files that you want to generate quizzes from inside the `Source` folder.
80
64
81
65
---
82
66
83
67
### Step 4: Install the Dependencies
68
+
84
69
1. Install all the required modules using this command:
85
70
```
86
71
pip install -r requirements.txt
87
72
```
88
73
89
-
90
74
---
91
75
92
76
### Step 5: Run the Script
77
+
93
78
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
79
```
95
80
python main.py
96
81
```
97
-
This will extract the text from the PDFs, generate multiple-choice questions (MCQs) using the language model, and save the output the folder named `Source`.
82
+
This will extract the text from the PDFs, generate multiple-choice questions (MCQs) using the language model, and save the output in a folder named `Generated_Quizes`.
98
83
99
84
---
100
85
101
-
## Rate Limits and Troubleshooting
102
-
Please note that the free tier of Groq API has rate limits, which may cause errors if too many requests are made in a short period of time. If you encounter a rate limit error, try reducing the number of PDFs in the 'Source' folder or lower the number of questions being generated. This should help avoid hitting the rate limits. For more information on the exact rate limits, please refer to the [Groq API documentation](https://console.groq.com/settings/limits).
86
+
## Output
87
+
88
+
The generated MCQ quiz will be saved in a text file with a timestamp in the `Generated_Quizes` folder. Each question will have four options, and the correct answer will be indicated.
89
+
90
+
## Author(s)
91
+
92
+
[Naman Verma](https://github.com/NamanVer02/)
93
+
94
+
## Disclaimers
95
+
96
+
Please note that the free tier of Groq API has rate limits, which may cause errors if too many requests are made in a short period of time. If you encounter a rate limit error, try reducing the number of PDFs in the 'Source' folder or lower the number of questions being generated. This should help avoid hitting the rate limits. For more information on the exact rate limits, please refer to the [Groq API documentation](https://console.groq.com/settings/limits).
0 commit comments