Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,13 +36,46 @@ def get_text_chunks(text):
|
|
36 |
text_chunks = text.split('\n\n') # Modify this based on your text splitting requirements
|
37 |
return text_chunks
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# Function to retrieve quiz data from the vector database
|
40 |
def retrieve_quiz_data(vectorDB, num_questions):
|
41 |
-
#
|
42 |
-
|
43 |
-
# For illustration purposes, assuming you have a function named 'query_vector_database'
|
44 |
-
quiz_data = query_vector_database(vectorDB, num_questions)
|
45 |
-
return quiz_data
|
46 |
|
47 |
# Function to generate quiz questions
|
48 |
def generate_quiz(quiz_name, quiz_topic, num_questions, pdf_content):
|
@@ -71,12 +104,6 @@ def generate_quiz(quiz_name, quiz_topic, num_questions, pdf_content):
|
|
71 |
if st.button('Save Vector Database'):
|
72 |
st.success('Vector Database Saved')
|
73 |
|
74 |
-
# Replace this function with your logic to query the vector database and get quiz data
|
75 |
-
def query_vector_database(vectorDB, num_questions):
|
76 |
-
# Implement your logic to query the vector database and retrieve quiz data
|
77 |
-
# This is a placeholder, replace it with your actual implementation
|
78 |
-
return [(f"Question {i + 1}", [f"Option {j}" for j in range(1, 5)], f"Option {i % 4 + 1}") for i in range(num_questions)]
|
79 |
-
|
80 |
if __name__ =='__main__':
|
81 |
st.set_page_config(page_title="CB Quiz Generator", page_icon="📝")
|
82 |
st.title('CB Quiz Generator')
|
|
|
36 |
text_chunks = text.split('\n\n') # Modify this based on your text splitting requirements
|
37 |
return text_chunks
|
38 |
|
39 |
+
# Function to process PDF and create vector database
|
40 |
+
def processing(pdf):
|
41 |
+
raw_text = get_pdf_text(pdf)
|
42 |
+
text_chunks = get_text_chunks(raw_text)
|
43 |
+
vectorDB = get_vectorstore(text_chunks)
|
44 |
+
return vectorDB
|
45 |
+
|
46 |
+
# Function to generate quiz questions, options, and correct answers
|
47 |
+
def generate_quiz_content(text, num_questions):
|
48 |
+
messages = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
49 |
+
for i in range(num_questions):
|
50 |
+
user_message = {'role': 'user', 'content': f'Generate question {i + 1} from the given text:\n{text}'}
|
51 |
+
messages.append(user_message)
|
52 |
+
|
53 |
+
response = openai.ChatCompletion.create(
|
54 |
+
model='gpt-3.5-turbo-16k',
|
55 |
+
messages=messages,
|
56 |
+
max_tokens=200,
|
57 |
+
temperature=0.7
|
58 |
+
)
|
59 |
+
quiz_data = []
|
60 |
+
|
61 |
+
for choice in response.get('choices', []):
|
62 |
+
content = choice.get('content', '').strip()
|
63 |
+
options_start = content.find("Options:") + len("Options:")
|
64 |
+
correct_answer_start = content.find("Correct Answer:") + len("Correct Answer:")
|
65 |
+
|
66 |
+
question = content[:options_start].strip()
|
67 |
+
options_str = content[options_start:correct_answer_start].strip()
|
68 |
+
correct_answer = content[correct_answer_start:].strip()
|
69 |
+
|
70 |
+
options = [opt.strip() for opt in options_str.split(',')]
|
71 |
+
quiz_data.append((question, options, correct_answer))
|
72 |
+
|
73 |
+
return quiz_data
|
74 |
+
|
75 |
# Function to retrieve quiz data from the vector database
|
76 |
def retrieve_quiz_data(vectorDB, num_questions):
|
77 |
+
# Replace this with your actual logic to query the vector database and retrieve quiz data
|
78 |
+
return [(f"Question {i + 1}", [f"Option {j}" for j in range(1, 5)], f"Option {i % 4 + 1}") for i in range(num_questions)]
|
|
|
|
|
|
|
79 |
|
80 |
# Function to generate quiz questions
|
81 |
def generate_quiz(quiz_name, quiz_topic, num_questions, pdf_content):
|
|
|
104 |
if st.button('Save Vector Database'):
|
105 |
st.success('Vector Database Saved')
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
if __name__ =='__main__':
|
108 |
st.set_page_config(page_title="CB Quiz Generator", page_icon="📝")
|
109 |
st.title('CB Quiz Generator')
|