mohammednouman commited on
Commit
15e614f
·
verified ·
1 Parent(s): 0c18ad3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -28,7 +28,7 @@ def get_pdf_text(pdf):
28
  return text
29
 
30
  def get_text_chunks(text: str):
31
- """ This function will split the text into smaller chunks"""
32
  text_splitter = RecursiveCharacterTextSplitter(
33
  chunk_size=1000,
34
  chunk_overlap=100,
@@ -39,29 +39,32 @@ def get_text_chunks(text: str):
39
  return chunks
40
 
41
  def get_vectorstore(text_chunks):
42
- """ This function will create a vector database as well as create and store the embedding of the text chunks into the VectorDB """
43
  embeddings = OpenAIEmbeddings()
44
  vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
45
  return vectorstore
46
 
47
  def search_vectorstore(vectorDB, query):
48
- """ This function searches for specific data or content in the vector database"""
49
  # Specify the search type
50
  search_type = 'similarity'
51
  search_results = vectorDB.search(query, search_type=search_type)
52
  return search_results
53
 
54
  def generate_quiz_questions(search_results, num_questions):
55
- """ Generate quiz questions with options using GPT-3.5-turbo-16k based on the search results """
56
  st.header(f"Quiz Generator: {quiz_name}")
57
  st.subheader(f"Topic: {quiz_topic}")
 
 
 
58
 
59
  # Placeholder for quiz questions
60
  quiz_questions = []
61
 
62
  # Generate questions using GPT-3.5-turbo-16k with the correct endpoint
63
  for i in range(num_questions):
64
- prompt = f"Generate a multiple-choice question and correct answer for the same related to:\n- {random.choice(search_results)}"
65
 
66
  # Prepare messages
67
  messages = [
@@ -108,7 +111,7 @@ if __name__ == '__main__':
108
  # User inputs
109
  quiz_name = st.text_input('Enter Quiz Name:')
110
  quiz_topic = st.text_input('Enter Quiz Topic:')
111
- num_questions = st.number_input('Enter Number of Questions:', min_value=1, value=1, step=1)
112
  pdf_content = st.file_uploader("Upload PDF Content for Questions:", type='pdf')
113
 
114
  # Generate quiz if all inputs are provided
 
28
  return text
29
 
30
  def get_text_chunks(text: str):
31
+ # This function will split the text into smaller chunks
32
  text_splitter = RecursiveCharacterTextSplitter(
33
  chunk_size=1000,
34
  chunk_overlap=100,
 
39
  return chunks
40
 
41
  def get_vectorstore(text_chunks):
42
+ # This function will create a vector database as well as create and store the embedding of the text chunks into the VectorDB
43
  embeddings = OpenAIEmbeddings()
44
  vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
45
  return vectorstore
46
 
47
  def search_vectorstore(vectorDB, query):
48
+ # This function searches for specific data or content in the vector database
49
  # Specify the search type
50
  search_type = 'similarity'
51
  search_results = vectorDB.search(query, search_type=search_type)
52
  return search_results
53
 
54
  def generate_quiz_questions(search_results, num_questions):
55
+ # Generate quiz questions with options using GPT-3.5-turbo-16k based on the search results
56
  st.header(f"Quiz Generator: {quiz_name}")
57
  st.subheader(f"Topic: {quiz_topic}")
58
+ # Process PDF and create vector database
59
+ if st.button('Generate Quiz'):
60
+ st.session_state['vectorDB'] = (pdf_content)
61
 
62
  # Placeholder for quiz questions
63
  quiz_questions = []
64
 
65
  # Generate questions using GPT-3.5-turbo-16k with the correct endpoint
66
  for i in range(num_questions):
67
+ prompt = f"As a highly intelligent and powerful quiz generator, your task is to Generate a different multiple-choice question and correct answer in a comprehensive and accurate format for the same related to:\n- {random.choice(search_results)} and the response generated by you should be comprehensive and relevant to the topic specified, you should not generate the same content multiple times in a single response, generate the explaination for each correct answer"
68
 
69
  # Prepare messages
70
  messages = [
 
111
  # User inputs
112
  quiz_name = st.text_input('Enter Quiz Name:')
113
  quiz_topic = st.text_input('Enter Quiz Topic:')
114
+ num_questions = st.number_input('Enter Number of Questions:', min_value=1, value=5, step=1)
115
  pdf_content = st.file_uploader("Upload PDF Content for Questions:", type='pdf')
116
 
117
  # Generate quiz if all inputs are provided