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)