AndrewRWilliams commited on
Commit
71c5936
·
1 Parent(s): 4c9a5c3

Update app.py with access code

Browse files
Files changed (1) hide show
  1. app.py +27 -21
app.py CHANGED
@@ -10,42 +10,48 @@ from openai import Completion as complete
10
  mcq_prompt = "Generate French MCQs on the above text. Each MCQ must have four choices. Generate ten questions with answers:"
11
 
12
  openai.api_key = os.environ["openai_api_key"]
 
13
 
14
- def generate_questions(context, mcq_prompt=mcq_prompt):
15
  """
16
  Generate questions by calling davinci-003.
17
  """
18
  prompt = context + mcq_prompt
19
-
20
- try:
21
- completion = complete.create(model="text-davinci-003", prompt=prompt, max_tokens=1875)
22
- return str(completion.choices[0].text)
23
- except Exception as e:
24
- # return str(e)
25
- # return python version
26
- return str(sys.version)
 
 
27
 
28
 
29
  # def append_completion(selected_text, feedback):
30
  # return selected_text, selected_text + feedback
31
-
32
-
33
  with gr.Blocks() as demo:
34
 
35
- gr.Markdown("Génération de quizz!")
36
-
37
- context = gr.Textbox(placeholder="insérez le texte ici.")
38
-
39
- qa_pairs = gr.Textbox(placeholder="Les questions apparaîtront ici.")
40
 
41
- #todo: test generating with just one phrase for one MCQ with smaller models
 
 
 
 
 
 
42
 
 
43
  quiz_button = gr.Button("Générer dix questions.")
44
 
45
- quiz_button.click(fn= generate_questions,
46
- inputs=context,
47
- outputs=qa_pairs
48
- )
 
 
49
 
50
  if __name__ == "__main__":
51
  demo.launch(debug=True, auth=("admin", "pass1234"))
 
10
  mcq_prompt = "Generate French MCQs on the above text. Each MCQ must have four choices. Generate ten questions with answers:"
11
 
12
  openai.api_key = os.environ["openai_api_key"]
13
+ access_code = os.environ["access_code"]
14
 
15
+ def generate_questions(context, credentials, mcq_prompt=mcq_prompt):
16
  """
17
  Generate questions by calling davinci-003.
18
  """
19
  prompt = context + mcq_prompt
20
+ if credentials == access_code:
21
+ try:
22
+ completion = complete.create(model="text-davinci-003", prompt=prompt, max_tokens=1875)
23
+ return str(completion.choices[0].text)
24
+ except Exception as e:
25
+ # return str(e)
26
+ # return python version
27
+ return str(sys.version)
28
+ else:
29
+ return "mauvais code d'accès"
30
 
31
 
32
  # def append_completion(selected_text, feedback):
33
  # return selected_text, selected_text + feedback
 
 
34
  with gr.Blocks() as demo:
35
 
36
+ with gr.Row():
 
 
 
 
37
 
38
+ gr.Markdown("Génération de quizz!")
39
+
40
+ context = gr.Textbox(placeholder="insérez le texte ici.")
41
+
42
+ qa_pairs = gr.Textbox(placeholder="Les questions apparaîtront ici.")
43
+
44
+ #todo: test generating with just one phrase for one MCQ with smaller models
45
 
46
+ credentials = gr.Textbox("Code d'accès.")
47
  quiz_button = gr.Button("Générer dix questions.")
48
 
49
+ if credentials == access_code:
50
+
51
+ quiz_button.click(fn= generate_questions,
52
+ inputs=[context, credentials],
53
+ outputs=qa_pairs
54
+ )
55
 
56
  if __name__ == "__main__":
57
  demo.launch(debug=True, auth=("admin", "pass1234"))