From ddcb04598c35e4e714eb7ebf6ee49cd614737467 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 13:59:45 +0530 Subject: [PATCH 01/11] Created main application --- llm_quiz_generator/main.py | 121 +++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 llm_quiz_generator/main.py diff --git a/llm_quiz_generator/main.py b/llm_quiz_generator/main.py new file mode 100644 index 000000000..f4d0856c8 --- /dev/null +++ b/llm_quiz_generator/main.py @@ -0,0 +1,121 @@ +""" +___________________________________________________________________________________________________________________________________________________ +| | +| To use this script, please check the README.md file in the directory. A quick start to get the project running is described here. | +| | +| 1. Create a Groq account and get your API key at https://console.groq.com/login. | +| | +| 2. Either: | +| - Add your API key directly to line 38: API_KEY = "your_groq_api_key_here", or | +| - Create a .env file in the same directory, and add GROQ_API_KEY=your_groq_api_key_here. | +| | +| 3. Place all your PDFs in a folder named ''Source'' in the same directory as this script. | +| | +| 4. Run the script: | +| python quiz_generator.py | +| | +| The generated MCQ quiz will be saved in a file called 'generated_mcq_quiz.txt'. | +|_________________________________________________________________________________________________________________________________________________| +""" + + +# Change this if you want to set the number of MCQ's +num_questions = 5 + + + +import os +from PyPDF2 import PdfReader +from langchain_groq import ChatGroq +from langchain.chains import RetrievalQA +from dotenv import load_dotenv, find_dotenv +from langchain_community.vectorstores import FAISS +from langchain_huggingface import HuggingFaceEmbeddings +from langchain.text_splitter import CharacterTextSplitter + + +load_dotenv(find_dotenv()) +API_KEY = os.environ["GROQ_API_KEY"] + + +def extract_text_from_pdfs(): + print(f"Extracting text from PDF files in the folder: '{'Source'}'...") + all_text = [] + for file_name in os.listdir('Source'): + if file_name.endswith(".pdf"): + file_path = os.path.join('Source', file_name) + print(f"Processing file: {file_name}") + reader = PdfReader(file_path) + for page in reader.pages: + all_text.append(page.extract_text()) + print("Text extraction completed.") + return " ".join(all_text) + + + +def generate_unique_mcq(text, num_questions=5): + print(f"Splitting text into chunks and creating embeddings for LLM processing...") + text_splitter = CharacterTextSplitter( + chunk_size=1000, + chunk_overlap=0 + ) + docs = text_splitter.create_documents([text]) + + embeddings = HuggingFaceEmbeddings() + store = FAISS.from_documents(docs, embeddings) + + print(f"Connecting to LLM to generate {num_questions} unique MCQs...") + llm = ChatGroq( + temperature=0.2, + model="llama-3.1-70b-versatile", + api_key=API_KEY + ) + + retrieval_chain = RetrievalQA.from_chain_type( + llm=llm, + chain_type="stuff", + retriever=store.as_retriever() + ) + + quiz = [] + query = f"Generate {num_questions} unique multiple choice questions from the following text: {text} " \ + f"Provide 4 answer options and also the correct answer in plaintext." + + response = retrieval_chain.invoke(query) + question_and_options = response['result'] + quiz.append(question_and_options) + + print("MCQ generation completed.") + return quiz + + + +def save_mcq_to_file(quiz, file_name="generated_mcq_quiz.txt"): + output_folder = "Generated_Quizes" + + if not os.path.exists(output_folder): + os.makedirs(output_folder) + print(f"Folder '{output_folder}' created.") + + file_path = os.path.join(output_folder, file_name) + + print(f"Saving the generated MCQs to file: '{file_path}'...") + with open(file_path, "w") as f: + for i, question in enumerate(quiz, 1): + f.write(f"Question {i}:\n{question}\n\n") + + print(f"MCQ Quiz saved to {file_path}") + + + +if __name__ == "__main__": + if not os.path.exists('Source'): + print(f"Folder '{'Source'}' not found.") + else: + print(f"Folder '{'Source'}' found. Starting process...") + text = extract_text_from_pdfs() + print("Text extracted from PDFs.") + + mcq_quiz = generate_unique_mcq(text, num_questions=num_questions) + save_mcq_to_file(mcq_quiz) + print("Process completed successfully.") From 6954d6c4a20f673050c4ad1b828f6c2481152c52 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 13:59:55 +0530 Subject: [PATCH 02/11] Added README --- llm_quiz_generator/README.md | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 llm_quiz_generator/README.md diff --git a/llm_quiz_generator/README.md b/llm_quiz_generator/README.md new file mode 100644 index 000000000..f197d19db --- /dev/null +++ b/llm_quiz_generator/README.md @@ -0,0 +1,98 @@ +# Automated Quiz Generator from PDF Files + +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. + +## Features + +- **Automatic PDF Text Extraction**: Extracts text from all PDFs in a specified folder. +- **MCQ Generation**: Generates unique multiple choice questions with 4 answer options and identifies the correct answer. +- **Quiz Output**: Saves the quiz in a text format for easy review. + +## Requirements + +The following Python packages are required to run the script: +- PyPDF2 +- langchain +- langchain_groq +- langchain_community +- langchain_huggingface +- faiss-cpu + +--- + +## How to Use the Automated Quiz Generator Script + +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. + + +### Step 1: Create a Groq Account and Get an API Key (100% free) + +1. **Visit Groq's Console**: + Open your web browser and go to [Groq Console](https://console.groq.com/login). + +2. **Log In or Create an Account**: + You can log in with your email, GitHub account, or create a new Groq account for free. + +3. **Generate an API Key**: + - After logging in, navigate to the "API Keys" section in the Groq console. + - Click the "Create API Key" button. + - Enter a name for your API key (e.g., `quiz_key`). + - **Important**: After you create the key, Groq will display it **only once**. Be sure to copy it correctly at this time. + +4. **Save the API Key**: + You will need this key to run the quiz generator script. + +--- + +### **Step 2: Add Your API Key to the Script** + +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. + + + +#### **Option 1: Store the API Key in a `.env` File** + +1. Create a new file in the same directory as your script and name it `.env`. +2. Open the `.env` file in a text editor. +3. Add the following line to the `.env` file, replacing your_groq_api_key_here with your actual API key: +``` +GROQ_API_KEY=your_groq_api_key_here +``` +4. Save the `.env` file + +#### **Option 2: Paste the API Key Directly into the Script** + +1. Open the `quiz_generator.py` file in your code editor. +2. Find the following line in the script (around line 38): + ```python + API_KEY = os.environ["GROQ_API_KEY"] + ``` +3. Replace the above line with your API key directly, like this: + ```python + API_KEY = "your_groq_api_key_here" + ``` + +--- + +### Step 3: Prepare the PDF files +1. Create a folder (if not present) called Sources in the same directory as your Python script. +2. Place all the PDF files that you want to generate quizzes from inside the Sources folder. + +--- + +### Step 4: Install the Dependencies +1. Install all the required modules using this command: +``` +pip install -r requirements.txt +``` + + +--- + +### Step 5: Run the Script +1. To generate the quiz, open a terminal or command prompt in the folder where the script is located and run the following command: +``` +python quiz_generator.py +``` +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`. + From 02e870b5d3b65c3d3acfe8dd26757d820301c24c Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 14:00:08 +0530 Subject: [PATCH 03/11] Added required modules --- llm_quiz_generator/requirements.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 llm_quiz_generator/requirements.txt diff --git a/llm_quiz_generator/requirements.txt b/llm_quiz_generator/requirements.txt new file mode 100644 index 000000000..7306b5e88 --- /dev/null +++ b/llm_quiz_generator/requirements.txt @@ -0,0 +1,6 @@ +PyPDF2 +langchain +langchain_groq +langchain_community +langchain_huggingface +faiss-cpu \ No newline at end of file From a87a2d1f275887b8cd6ebed2e04abd4241a31de6 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 14:01:31 +0530 Subject: [PATCH 04/11] Fixed folder name --- llm_quiz_generator/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llm_quiz_generator/README.md b/llm_quiz_generator/README.md index f197d19db..6af4ff9c9 100644 --- a/llm_quiz_generator/README.md +++ b/llm_quiz_generator/README.md @@ -75,8 +75,8 @@ GROQ_API_KEY=your_groq_api_key_here --- ### Step 3: Prepare the PDF files -1. Create a folder (if not present) called Sources in the same directory as your Python script. -2. Place all the PDF files that you want to generate quizzes from inside the Sources folder. +1. Create a folder (if not present) called `Source` in the same directory as your Python script. +2. Place all the PDF files that you want to generate quizzes from inside the `Source` folder. --- @@ -94,5 +94,5 @@ pip install -r requirements.txt ``` python quiz_generator.py ``` -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`. +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`. From 5539667775cfc3726e6cf3c4976ac01c03b53b0f Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 14:09:54 +0530 Subject: [PATCH 05/11] added date time to output file name --- llm_quiz_generator/main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/llm_quiz_generator/main.py b/llm_quiz_generator/main.py index f4d0856c8..252248d00 100644 --- a/llm_quiz_generator/main.py +++ b/llm_quiz_generator/main.py @@ -26,6 +26,7 @@ import os from PyPDF2 import PdfReader +from datetime import datetime from langchain_groq import ChatGroq from langchain.chains import RetrievalQA from dotenv import load_dotenv, find_dotenv @@ -41,6 +42,12 @@ def extract_text_from_pdfs(): print(f"Extracting text from PDF files in the folder: '{'Source'}'...") all_text = [] + + if len(os.listdir('Source')) == 0: + print("Source Folder Empty!") + print("Process exiting...") + exit(0) + for file_name in os.listdir('Source'): if file_name.endswith(".pdf"): file_path = os.path.join('Source', file_name) @@ -97,6 +104,8 @@ def save_mcq_to_file(quiz, file_name="generated_mcq_quiz.txt"): os.makedirs(output_folder) print(f"Folder '{output_folder}' created.") + current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + file_name = f"generated_mcq_quiz_{current_time}.txt" file_path = os.path.join(output_folder, file_name) print(f"Saving the generated MCQs to file: '{file_path}'...") From 4ab93c72237569979ff15e0e9c30f42a729f03b7 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 15:19:23 +0530 Subject: [PATCH 06/11] updated filenames --- llm_quiz_generator/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llm_quiz_generator/README.md b/llm_quiz_generator/README.md index 6af4ff9c9..068b890b5 100644 --- a/llm_quiz_generator/README.md +++ b/llm_quiz_generator/README.md @@ -62,7 +62,7 @@ GROQ_API_KEY=your_groq_api_key_here #### **Option 2: Paste the API Key Directly into the Script** -1. Open the `quiz_generator.py` file in your code editor. +1. Open the `main.py` file in your code editor. 2. Find the following line in the script (around line 38): ```python API_KEY = os.environ["GROQ_API_KEY"] @@ -92,7 +92,7 @@ pip install -r requirements.txt ### Step 5: Run the Script 1. To generate the quiz, open a terminal or command prompt in the folder where the script is located and run the following command: ``` -python quiz_generator.py +python main.py ``` 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`. From cd11ce2291a656a5dfa5fb4fcf57688eb30eb32a Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 16:50:22 +0530 Subject: [PATCH 07/11] Linting --- llm_quiz_generator/main.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/llm_quiz_generator/main.py b/llm_quiz_generator/main.py index 252248d00..3655822b1 100644 --- a/llm_quiz_generator/main.py +++ b/llm_quiz_generator/main.py @@ -9,7 +9,7 @@ | - Add your API key directly to line 38: API_KEY = "your_groq_api_key_here", or | | - Create a .env file in the same directory, and add GROQ_API_KEY=your_groq_api_key_here. | | | -| 3. Place all your PDFs in a folder named ''Source'' in the same directory as this script. | +| 3. Place all your PDFs in a folder named 'Source' in the same directory as this script. | | | | 4. Run the script: | | python quiz_generator.py | @@ -23,7 +23,6 @@ num_questions = 5 - import os from PyPDF2 import PdfReader from datetime import datetime @@ -40,11 +39,11 @@ def extract_text_from_pdfs(): - print(f"Extracting text from PDF files in the folder: '{'Source'}'...") + print(f"Extracting text from PDF files in the folder: 'Source'...") all_text = [] - if len(os.listdir('Source')) == 0: - print("Source Folder Empty!") + if not os.path.exists('Source') or not os.listdir('Source'): + print("Folder 'Source' is empty or not found!") print("Process exiting...") exit(0) @@ -58,8 +57,6 @@ def extract_text_from_pdfs(): print("Text extraction completed.") return " ".join(all_text) - - def generate_unique_mcq(text, num_questions=5): print(f"Splitting text into chunks and creating embeddings for LLM processing...") text_splitter = CharacterTextSplitter( @@ -95,8 +92,6 @@ def generate_unique_mcq(text, num_questions=5): print("MCQ generation completed.") return quiz - - def save_mcq_to_file(quiz, file_name="generated_mcq_quiz.txt"): output_folder = "Generated_Quizes" @@ -115,13 +110,11 @@ def save_mcq_to_file(quiz, file_name="generated_mcq_quiz.txt"): print(f"MCQ Quiz saved to {file_path}") - - if __name__ == "__main__": if not os.path.exists('Source'): - print(f"Folder '{'Source'}' not found.") + print(f"Folder 'Source' not found.") else: - print(f"Folder '{'Source'}' found. Starting process...") + print(f"Folder 'Source' found. Starting process...") text = extract_text_from_pdfs() print("Text extracted from PDFs.") From 8488e336563fb988bea34c65c64022c760386e72 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 16:53:38 +0530 Subject: [PATCH 08/11] added rate limit troubleshooting --- llm_quiz_generator/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llm_quiz_generator/README.md b/llm_quiz_generator/README.md index 068b890b5..08733a39a 100644 --- a/llm_quiz_generator/README.md +++ b/llm_quiz_generator/README.md @@ -96,3 +96,7 @@ python main.py ``` 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`. +--- + +## Rate Limits and Troubleshooting +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). \ No newline at end of file From 83d39ddefd5f6f837400f7648f0a8b2e7f789425 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 17:15:01 +0530 Subject: [PATCH 09/11] flake8 linting --- llm_quiz_generator/main.py | 70 +++++++++++++++----------------------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/llm_quiz_generator/main.py b/llm_quiz_generator/main.py index 3655822b1..32a155c13 100644 --- a/llm_quiz_generator/main.py +++ b/llm_quiz_generator/main.py @@ -1,28 +1,3 @@ -""" -___________________________________________________________________________________________________________________________________________________ -| | -| To use this script, please check the README.md file in the directory. A quick start to get the project running is described here. | -| | -| 1. Create a Groq account and get your API key at https://console.groq.com/login. | -| | -| 2. Either: | -| - Add your API key directly to line 38: API_KEY = "your_groq_api_key_here", or | -| - Create a .env file in the same directory, and add GROQ_API_KEY=your_groq_api_key_here. | -| | -| 3. Place all your PDFs in a folder named 'Source' in the same directory as this script. | -| | -| 4. Run the script: | -| python quiz_generator.py | -| | -| The generated MCQ quiz will be saved in a file called 'generated_mcq_quiz.txt'. | -|_________________________________________________________________________________________________________________________________________________| -""" - - -# Change this if you want to set the number of MCQ's -num_questions = 5 - - import os from PyPDF2 import PdfReader from datetime import datetime @@ -33,20 +8,23 @@ from langchain_huggingface import HuggingFaceEmbeddings from langchain.text_splitter import CharacterTextSplitter - load_dotenv(find_dotenv()) API_KEY = os.environ["GROQ_API_KEY"] +# Change this if you want to set the number of MCQs +num_questions = 5 + def extract_text_from_pdfs(): - print(f"Extracting text from PDF files in the folder: 'Source'...") + """Extracts text from PDF files in the 'Source' folder.""" + print("Extracting text from PDF files in the folder: 'Source'...") all_text = [] - - if not os.path.exists('Source') or not os.listdir('Source'): - print("Folder 'Source' is empty or not found!") + + if len(os.listdir('Source')) == 0: + print("Source Folder Empty!") print("Process exiting...") exit(0) - + for file_name in os.listdir('Source'): if file_name.endswith(".pdf"): file_path = os.path.join('Source', file_name) @@ -57,8 +35,10 @@ def extract_text_from_pdfs(): print("Text extraction completed.") return " ".join(all_text) + def generate_unique_mcq(text, num_questions=5): - print(f"Splitting text into chunks and creating embeddings for LLM processing...") + """Generates unique multiple choice questions from text.""" + print("LLM processing...") text_splitter = CharacterTextSplitter( chunk_size=1000, chunk_overlap=0 @@ -82,9 +62,12 @@ def generate_unique_mcq(text, num_questions=5): ) quiz = [] - query = f"Generate {num_questions} unique multiple choice questions from the following text: {text} " \ - f"Provide 4 answer options and also the correct answer in plaintext." - + query = ( + f"Generate {num_questions} unique multiple choice questions" + "from the text: {text}" + "Provide 4 answer options and also the correct answer in plaintext." + ) + response = retrieval_chain.invoke(query) question_and_options = response['result'] quiz.append(question_and_options) @@ -92,32 +75,35 @@ def generate_unique_mcq(text, num_questions=5): print("MCQ generation completed.") return quiz + def save_mcq_to_file(quiz, file_name="generated_mcq_quiz.txt"): + """Saves generated MCQs to a text file.""" output_folder = "Generated_Quizes" - + if not os.path.exists(output_folder): os.makedirs(output_folder) print(f"Folder '{output_folder}' created.") - + current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") file_name = f"generated_mcq_quiz_{current_time}.txt" file_path = os.path.join(output_folder, file_name) - + print(f"Saving the generated MCQs to file: '{file_path}'...") with open(file_path, "w") as f: for i, question in enumerate(quiz, 1): f.write(f"Question {i}:\n{question}\n\n") - + print(f"MCQ Quiz saved to {file_path}") + if __name__ == "__main__": if not os.path.exists('Source'): - print(f"Folder 'Source' not found.") + print("Folder 'Source' not found.") else: - print(f"Folder 'Source' found. Starting process...") + print("Folder 'Source' found. Starting process...") text = extract_text_from_pdfs() print("Text extracted from PDFs.") - + mcq_quiz = generate_unique_mcq(text, num_questions=num_questions) save_mcq_to_file(mcq_quiz) print("Process completed successfully.") From 87a133df4062afc7c7683f2d266fc013925c3d08 Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Fri, 11 Oct 2024 17:15:19 +0530 Subject: [PATCH 10/11] Readme template --- llm_quiz_generator/README.md | 68 ++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/llm_quiz_generator/README.md b/llm_quiz_generator/README.md index 08733a39a..aeaa7681c 100644 --- a/llm_quiz_generator/README.md +++ b/llm_quiz_generator/README.md @@ -1,30 +1,15 @@ # Automated Quiz Generator from PDF Files -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. - -## Features +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. - **Automatic PDF Text Extraction**: Extracts text from all PDFs in a specified folder. - **MCQ Generation**: Generates unique multiple choice questions with 4 answer options and identifies the correct answer. - **Quiz Output**: Saves the quiz in a text format for easy review. -## Requirements - -The following Python packages are required to run the script: -- PyPDF2 -- langchain -- langchain_groq -- langchain_community -- langchain_huggingface -- faiss-cpu - ---- - -## How to Use the Automated Quiz Generator Script +## Setup Instructions 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. - ### Step 1: Create a Groq Account and Get an API Key (100% free) 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 --- -### **Step 2: Add Your API Key to the Script** - -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. +### Step 2: Add Your API Key to the Script +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. - -#### **Option 1: Store the API Key in a `.env` File** +#### Option 1: Store the API Key in a `.env` File 1. Create a new file in the same directory as your script and name it `.env`. 2. Open the `.env` file in a text editor. -3. Add the following line to the `.env` file, replacing your_groq_api_key_here with your actual API key: +3. Add the following line to the `.env` file, replacing `your_groq_api_key_here` with your actual API key: ``` -GROQ_API_KEY=your_groq_api_key_here +GROQ_API_KEY="your_groq_api_key_here" ``` -4. Save the `.env` file +4. Save the `.env` file. -#### **Option 2: Paste the API Key Directly into the Script** +#### Option 2: Paste the API Key Directly into the Script 1. Open the `main.py` file in your code editor. 2. Find the following line in the script (around line 38): - ```python - API_KEY = os.environ["GROQ_API_KEY"] - ``` + ```python + API_KEY = os.environ["GROQ_API_KEY"] + ``` 3. Replace the above line with your API key directly, like this: - ```python - API_KEY = "your_groq_api_key_here" - ``` + ```python + API_KEY = "your_groq_api_key_here" + ``` --- -### Step 3: Prepare the PDF files +### Step 3: Prepare the PDF Files + 1. Create a folder (if not present) called `Source` in the same directory as your Python script. 2. Place all the PDF files that you want to generate quizzes from inside the `Source` folder. --- ### Step 4: Install the Dependencies + 1. Install all the required modules using this command: ``` pip install -r requirements.txt ``` - --- ### Step 5: Run the Script + 1. To generate the quiz, open a terminal or command prompt in the folder where the script is located and run the following command: ``` python main.py ``` -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`. +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`. --- -## Rate Limits and Troubleshooting -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). \ No newline at end of file +## Output + +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. + +## Author(s) + +[Naman Verma](https://github.com/NamanVer02/) + +## Disclaimers + +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). From 55aa1879dc4c95a2898a0c7d9666b6739153873c Mon Sep 17 00:00:00 2001 From: NamanVer02 Date: Sat, 12 Oct 2024 12:25:56 +0530 Subject: [PATCH 11/11] added module versions --- llm_quiz_generator/requirements.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/llm_quiz_generator/requirements.txt b/llm_quiz_generator/requirements.txt index 7306b5e88..087e22335 100644 --- a/llm_quiz_generator/requirements.txt +++ b/llm_quiz_generator/requirements.txt @@ -1,6 +1,6 @@ -PyPDF2 -langchain -langchain_groq -langchain_community -langchain_huggingface -faiss-cpu \ No newline at end of file +PyPDF2==3.0.1 +langchain==0.3.3 +langchain_groq==0.2.0 +langchain_community==0.3.2 +langchain_huggingface==0.1.0 +faiss-cpu==1.9.0 \ No newline at end of file