import gradio as gr import random from llm import get_prompt, get_responce def generate_questions(question_type): prompt, seed = get_prompt(question_type) questions = get_responce(prompt) return questions, seed def process_question_type(question_type): questions, seed = generate_questions(question_type) formatted_questions = [] for question in questions: question_text = question["question"] options = question.get("options", {}) answer = question["answer"] correction = question.get("correction", "") question_display = { "Question": question_text, "Answer": answer, "Correction": correction, "Options": options if options else None, } formatted_questions.append(question_display) return formatted_questions, seed def main(): question_types = [ "Choose the correct meaning of the word", "Personal response", "Give reasons", "Fill in the blanks", "True or False", ] # Create a Gradio interface with gr.Blocks() as demo: gr.Markdown("

Select Question Type

") question_type = gr.Dropdown(choices=question_types, label="Question Type", value=question_types[0]) generate_button = gr.Button("Generate Questions") output = gr.Textbox(label="Generated Questions", interactive=False) seed_output = gr.Textbox(label="Seed Number", interactive=False) def generate(): questions, seed = process_question_type(question_type.value) formatted_output = "\n".join([f"{q['Question']} - Answer: {q['Answer']}, Correction: {q['Correction']}" for q in questions]) return formatted_output, seed generate_button.click(generate, outputs=[output, seed_output]) demo.launch() if __name__ == "__main__": main()