AndrewRWilliams commited on
Commit
4581c90
·
1 Parent(s): 0e5ead4

add app file

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import transformers
4
+
5
+ import os
6
+ import sys
7
+ import openai
8
+ from openai import Completion as complete
9
+
10
+ openai.api_key = "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"
11
+
12
+ def generate_questions(context, mcq_prompt=mcq_prompt):
13
+ """
14
+ Generate questions by calling davinci-003.
15
+ """
16
+ prompt = context + mcq_prompt
17
+
18
+ try:
19
+ completion = complete.create(model="text-davinci-003", prompt=prompt, max_tokens=1875)
20
+ return str(completion.choices[0].text)
21
+ except Exception as e:
22
+ # return str(e)
23
+ # return python version
24
+ return str(sys.version)
25
+
26
+
27
+ # def append_completion(selected_text, feedback):
28
+ # return selected_text, selected_text + feedback
29
+
30
+
31
+ with gr.Blocks() as demo:
32
+
33
+ gr.Markdown("Génération de quizz!")
34
+
35
+ context = gr.Textbox(placeholder="insérez le texte ici.")
36
+
37
+ qa_pairs = gr.Textbox(placeholder="Les questions apparaîtront ici.")
38
+
39
+ mcq_prompt = "Generate French MCQs on the above text. Each MCQ must have four choices. Generate ten questions with answers:"
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)