File size: 1,330 Bytes
4581c90
 
 
 
 
 
 
 
 
06b74c7
 
4581c90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

import gradio as gr
import transformers

import os
import sys
import openai
from openai import Completion as complete

mcq_prompt = "Generate French MCQs on the above text. Each MCQ must have four choices. Generate ten questions with answers:"

def generate_questions(context, mcq_prompt=mcq_prompt):
    """
    Generate questions by calling davinci-003.
    """
    prompt = context + mcq_prompt
    
    try:
        completion = complete.create(model="text-davinci-003", prompt=prompt, max_tokens=1875)
        return str(completion.choices[0].text)
    except Exception as e:
        # return str(e)
        # return python version
        return str(sys.version)


# def append_completion(selected_text, feedback):
#     return selected_text, selected_text + feedback


with gr.Blocks() as demo:

    gr.Markdown("Génération de quizz!")

    context = gr.Textbox(placeholder="insérez le texte ici.")

    qa_pairs = gr.Textbox(placeholder="Les questions apparaîtront ici.")

    #todo: test generating with just one phrase for one MCQ with smaller models

    quiz_button = gr.Button("Générer dix questions.")

    quiz_button.click(fn= generate_questions,
                      inputs=context,	
                      outputs=qa_pairs
                    )

if __name__ == "__main__":
    demo.launch(debug=True)