9
9
| - Add your API key directly to line 38: API_KEY = "your_groq_api_key_here", or |
10
10
| - Create a .env file in the same directory, and add GROQ_API_KEY=your_groq_api_key_here. |
11
11
| |
12
- | 3. Place all your PDFs in a folder named '' Source'' in the same directory as this script. |
12
+ | 3. Place all your PDFs in a folder named 'Source' in the same directory as this script. |
13
13
| |
14
14
| 4. Run the script: |
15
15
| python quiz_generator.py |
23
23
num_questions = 5
24
24
25
25
26
-
27
26
import os
28
27
from PyPDF2 import PdfReader
29
28
from datetime import datetime
40
39
41
40
42
41
def extract_text_from_pdfs ():
43
- print (f"Extracting text from PDF files in the folder: '{ ' Source' } '..." )
42
+ print (f"Extracting text from PDF files in the folder: 'Source'..." )
44
43
all_text = []
45
44
46
- if len ( os .listdir ('Source' )) == 0 :
47
- print ("Source Folder Empty !" )
45
+ if not os .path . exists ('Source' ) or not os . listdir ( 'Source' ) :
46
+ print ("Folder ' Source' is empty or not found !" )
48
47
print ("Process exiting..." )
49
48
exit (0 )
50
49
@@ -58,8 +57,6 @@ def extract_text_from_pdfs():
58
57
print ("Text extraction completed." )
59
58
return " " .join (all_text )
60
59
61
-
62
-
63
60
def generate_unique_mcq (text , num_questions = 5 ):
64
61
print (f"Splitting text into chunks and creating embeddings for LLM processing..." )
65
62
text_splitter = CharacterTextSplitter (
@@ -95,8 +92,6 @@ def generate_unique_mcq(text, num_questions=5):
95
92
print ("MCQ generation completed." )
96
93
return quiz
97
94
98
-
99
-
100
95
def save_mcq_to_file (quiz , file_name = "generated_mcq_quiz.txt" ):
101
96
output_folder = "Generated_Quizes"
102
97
@@ -115,13 +110,11 @@ def save_mcq_to_file(quiz, file_name="generated_mcq_quiz.txt"):
115
110
116
111
print (f"MCQ Quiz saved to { file_path } " )
117
112
118
-
119
-
120
113
if __name__ == "__main__" :
121
114
if not os .path .exists ('Source' ):
122
- print (f"Folder '{ ' Source' } ' not found." )
115
+ print (f"Folder 'Source' not found." )
123
116
else :
124
- print (f"Folder '{ ' Source' } ' found. Starting process..." )
117
+ print (f"Folder 'Source' found. Starting process..." )
125
118
text = extract_text_from_pdfs ()
126
119
print ("Text extracted from PDFs." )
127
120
0 commit comments