Spaces:
Sleeping
Sleeping
mohammed3536
commited on
Commit
•
33f1328
1
Parent(s):
03e805e
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,19 @@ def processing(pdf):
|
|
41 |
vectorDB = get_vectorstore(text_chunks)
|
42 |
return vectorDB
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
def generate_quiz(quiz_name, quiz_topic, num_questions, pdf_content):
|
46 |
st.header(f"Quiz Generator: {quiz_name}")
|
47 |
st.subheader(f"Topic: {quiz_topic}")
|
@@ -51,23 +63,28 @@ def generate_quiz(quiz_name, quiz_topic, num_questions, pdf_content):
|
|
51 |
st.session_state['vectorDB'] = processing(pdf_content)
|
52 |
st.success('PDF Processed and Vector Database Created')
|
53 |
|
54 |
-
# Generate Quiz Questions
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
for
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
# Save button to store vector database
|
73 |
if st.session_state.vectorDB:
|
|
|
41 |
vectorDB = get_vectorstore(text_chunks)
|
42 |
return vectorDB
|
43 |
|
44 |
+
|
45 |
+
# Function to generate questions using OpenAI GPT-3
|
46 |
+
def generate_questions(text, num_questions):
|
47 |
+
prompt = f"Generate {num_questions} questions from the given text:\n{text}"
|
48 |
+
response = openai.Completion.create(
|
49 |
+
engine="gpt-3.5-turbo", # You can use another engine if needed
|
50 |
+
prompt=prompt,
|
51 |
+
max_tokens=200
|
52 |
+
)
|
53 |
+
questions = [choice['text'].strip() for choice in response['choices']]
|
54 |
+
return questions
|
55 |
+
|
56 |
+
# Modified generate_quiz function
|
57 |
def generate_quiz(quiz_name, quiz_topic, num_questions, pdf_content):
|
58 |
st.header(f"Quiz Generator: {quiz_name}")
|
59 |
st.subheader(f"Topic: {quiz_topic}")
|
|
|
63 |
st.session_state['vectorDB'] = processing(pdf_content)
|
64 |
st.success('PDF Processed and Vector Database Created')
|
65 |
|
66 |
+
# Generate Quiz Questions using OpenAI GPT-3.5
|
67 |
+
if st.session_state.vectorDB:
|
68 |
+
raw_text = get_pdf_text(pdf_content)
|
69 |
+
generated_questions = generate_questions(raw_text, num_questions)
|
70 |
+
|
71 |
+
# Display and collect user input for each generated question
|
72 |
+
for i, generated_question in enumerate(generated_questions):
|
73 |
+
st.subheader(f"Question {i + 1}")
|
74 |
+
question = st.text_input(f"Generated Question: {generated_question}", key=f"question_{i + 1}")
|
75 |
+
|
76 |
+
# Collect options and correct answer
|
77 |
+
options = []
|
78 |
+
for j in range(1, 5):
|
79 |
+
option = st.text_input(f"Option {j}:", key=f"option_{i + 1}_{j}")
|
80 |
+
options.append(option)
|
81 |
+
|
82 |
+
correct_answer = st.selectbox(f"Correct Answer for Question {i + 1}:", options=options, key=f"correct_answer_{i + 1}")
|
83 |
+
|
84 |
+
# Save question, options, and correct answer in vector database
|
85 |
+
# (Replace the following line with your logic to store in the vector database)
|
86 |
+
if st.button(f'Save Question {i + 1}'):
|
87 |
+
st.success(f'Question {i + 1} Saved!')
|
88 |
|
89 |
# Save button to store vector database
|
90 |
if st.session_state.vectorDB:
|