muhh-b commited on
Commit
d69b94f
β€’
1 Parent(s): 306eb78

Update quiz_generation.py

Browse files
Files changed (1) hide show
  1. quiz_generation.py +22 -7
quiz_generation.py CHANGED
@@ -5,7 +5,6 @@ from oauth2client import client, file, tools
5
  import bardapi
6
  import streamlit
7
 
8
-
9
  SCOPES = "https://www.googleapis.com/auth/forms.body"
10
  DISCOVERY_DOC = "https://forms.googleapis.com/$discovery/rest?version=v1"
11
 
@@ -15,15 +14,24 @@ NEW_FORM = {
15
  }
16
  }
17
 
18
-
19
  def generate_quiz_questions(prompt):
20
- # Set your Bard API key as an environment variable
 
 
 
21
 
 
 
 
 
 
 
 
22
  os.environ['_BARD_API_KEY'] = st.secrets["bard_api_key"]
23
 
24
  prompt_suffix = ". Each generated question has to begin with 'πŸ”Ή', each choice has to begin with 'πŸ”Έ', and each correct answer has to begin with 'βœ”οΈ'."
25
 
26
-
27
  # Send API requests and get responses
28
  response = bardapi.core.Bard().get_answer(prompt + prompt_suffix)
29
 
@@ -31,8 +39,17 @@ def generate_quiz_questions(prompt):
31
 
32
  return quiz
33
 
34
-
35
  def generate_quiz_url(prompt_text, form_service):
 
 
 
 
 
 
 
 
 
36
  # Generate quiz questions based on the transcribed text
37
  text = generate_quiz_questions(prompt_text)
38
 
@@ -105,6 +122,4 @@ def generate_quiz_url(prompt_text, form_service):
105
  # Construct the quiz link using the form ID
106
  form_url = result["responderUri"]
107
 
108
-
109
  return form_url
110
-
 
5
  import bardapi
6
  import streamlit
7
 
 
8
  SCOPES = "https://www.googleapis.com/auth/forms.body"
9
  DISCOVERY_DOC = "https://forms.googleapis.com/$discovery/rest?version=v1"
10
 
 
14
  }
15
  }
16
 
17
+ # Function to generate quiz questions based on a given prompt
18
  def generate_quiz_questions(prompt):
19
+ '''Generates quiz questions based on a given prompt using the Bard API.
20
+
21
+ Args:
22
+ prompt (str): The prompt for generating quiz questions.
23
 
24
+ Returns:
25
+ str: The generated quiz questions in a formatted text.
26
+ '''
27
+ # Visit https://bard.google.com/
28
+ # F12 for console
29
+ # Session: Application β†’ Cookies β†’ Copy the value of __Secure-1PSID cookie.
30
+ # Set your __Secure-1PSID value to key
31
  os.environ['_BARD_API_KEY'] = st.secrets["bard_api_key"]
32
 
33
  prompt_suffix = ". Each generated question has to begin with 'πŸ”Ή', each choice has to begin with 'πŸ”Έ', and each correct answer has to begin with 'βœ”οΈ'."
34
 
 
35
  # Send API requests and get responses
36
  response = bardapi.core.Bard().get_answer(prompt + prompt_suffix)
37
 
 
39
 
40
  return quiz
41
 
42
+ # Function to generate the quiz URL based on the transcribed text
43
  def generate_quiz_url(prompt_text, form_service):
44
+ '''Generates the quiz URL based on the transcribed text and form service.
45
+
46
+ Args:
47
+ prompt_text (str): The transcribed text used for generating quiz questions.
48
+ form_service (googleapiclient.discovery.Resource): The form service object for creating the form.
49
+
50
+ Returns:
51
+ str: The URL of the generated quiz form.
52
+ '''
53
  # Generate quiz questions based on the transcribed text
54
  text = generate_quiz_questions(prompt_text)
55
 
 
122
  # Construct the quiz link using the form ID
123
  form_url = result["responderUri"]
124
 
 
125
  return form_url