import requests import gradio as gr from helper import generate_access_token def generate_mcq_questions(grade, board, subject, topics, number_of_questions, multiple_answer, single_answer, easy, medium, hard, remember, understand, apply, analyze, evaluate, create, hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy, solution_sheet): data = { "institution_id": "string", "teacher_id": "string", "board": board, "grade": grade, "subject": subject, "topics": topics.split(", "), "number_of_questions": number_of_questions, "question_type_distribution_percentage": { "multiple_answer": multiple_answer, "single_answer": single_answer, }, "difficulty_distribution_percentage": { "easy": easy, "medium": medium, "hard": hard }, "blooms_taxonomy_distribution_percentage": { "Remember": remember, "Understand": understand, "Apply": apply, "Analyze": analyze, "Evaluate": evaluate, "Create": create }, "question_tagging_options": { "Hint": hint, "Curricular_Goal": curricular_goal, "Competency": competency, "LO": lo, "LOB": lob, "Difficulty_level": difficulty_level, "Bloom_Taxonomy": bloom_taxonomy }, "solution_sheet": solution_sheet } print(data) access_token = generate_access_token() if access_token is None: return {"Error": "Failed to generate access token"} response = requests.post("http://20.193.151.200:8080/v1/k12/generate/mcqs", headers={ "accept": "application/json", "content-type": "application/json", "Authorization": f"{access_token}"}, json=data) if(str(response.status_code)[0] != '2'): return {"Error": f"{response.status_code}"} return response.json() def get_mcq_questions(request_id): access_token = generate_access_token() if access_token is None: return {"Error": "Failed to generate access token"} url = f"http://20.193.151.200:8080/v1/k12/generate/mcqs/{request_id}" headers = {"accept": "application/json", "Authorization": access_token} response = requests.get(url, headers=headers) if response.status_code == 200: return response.json() else: return {"Error" : f"{response.status_code}"} def post_interface(): with gr.Blocks() as post_page: grade = gr.Textbox(label="Grade", value="6") board = gr.Textbox(label="Board", value="NCERT") subject = gr.Textbox(label="Subject", value="Science") topics = gr.Textbox(label="Topics (comma-separated)", value="Light") number_of_questions = gr.Number(label="Number of Questions", value=20) gr.Markdown("## Question Type (Multiple Answer, Single Answer) - Absolute") with gr.Row(): with gr.Column(): multiple_answer = gr.Number(label="Multiple Answer Questions", minimum=0, maximum=100, value=0) with gr.Column(): single_answer = gr.Number(label="Single Answer Questions", minimum=0, maximum=100, value=0) # easy = gr.Slider(label="Easy Questions (%)", minimum=0, maximum=100, value=0) # medium = gr.Slider(label="Medium Questions (%)", minimum=0, maximum=100, value=0) # hard = gr.Slider(label="Hard Questions (%)", minimum=0, maximum=100, value=0) gr.Markdown("## Difficulty Distribution (easy, medium, hard) - Percentage") # Difficulty Distribution (easy, medium, hard) with gr.Row(): with gr.Column(): easy = gr.Number(label="Easy", minimum=0, maximum=100, value=0) with gr.Column(): medium = gr.Number(label="Medium", minimum=0, maximum=100, value=0) with gr.Column(): hard = gr.Number(label="Hard", minimum=0, maximum=100, value=0) # remember = gr.Slider(label="Remember (%)", minimum=0, maximum=100, value=0) # understand = gr.Slider(label="Understand (%)", minimum=0, maximum=100, value=0) # apply = gr.Slider(label="Apply (%)", minimum=0, maximum=100, value=0) # analyze = gr.Slider(label="Analyze (%)", minimum=0, maximum=100, value=0) # evaluate = gr.Slider(label="Evaluate (%)", minimum=0, maximum=100, value=0) # create = gr.Slider(label="Create (%)", minimum=0, maximum=100, value=0) gr.Markdown("## Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create) - Percentage") # Bloom Taxonomy Distribution (Remember, Understand, Apply, Analyze, Evaluate, Create) with gr.Row(): with gr.Column(): remember = gr.Number(minimum=0, maximum=100, step=1, label="Remember", value=0) with gr.Column(): understand = gr.Number(minimum=0, maximum=100, step=1, label="Understand", value=0) with gr.Column(): apply = gr.Number(minimum=0, maximum=100, step=1, label="Apply", value=0) with gr.Row(): with gr.Column(): analyze = gr.Number(minimum=0, maximum=100, step=1, label="Analyze", value=0) with gr.Column(): evaluate = gr.Number(minimum=0, maximum=100, step=1, label="Evaluate", value=0) with gr.Column(): create = gr.Number(minimum=0, maximum=100, step=1, label="Create", value=0) hint = gr.Radio(label="Hint", choices=["Yes", "No"], value="No") curricular_goal = gr.Radio(label="Curricular Goal", choices=["Yes", "No"], value="No") competency = gr.Radio(label="Competency", choices=["Yes", "No"], value="No") lo = gr.Radio(label="LO", choices=["Yes", "No"], value="No") lob = gr.Radio(label="LOB", choices=["Yes", "No"], value="No") difficulty_level = gr.Radio(label="Difficulty Level", choices=["Yes", "No"], value="No") bloom_taxonomy = gr.Radio(label="Bloom Taxonomy", choices=["Yes", "No"], value="No") solution_sheet = gr.Radio(label="Solution Sheet", choices=["Yes", "No"], value="Yes") submit_button = gr.Button("Invoke Request") submit_button.click(generate_mcq_questions, inputs= [grade, board, subject, topics, number_of_questions, multiple_answer, single_answer, easy, medium, hard, remember, understand, apply, analyze, evaluate, create, hint, curricular_goal, competency, lo, lob, difficulty_level, bloom_taxonomy, solution_sheet], outputs=gr.JSON()) return post_page def get_interface(): with gr.Blocks() as get_page: interface = gr.Interface( fn=get_mcq_questions, inputs=gr.Textbox(label="Enter Request ID"), outputs="json", ) return get_page def mcq_generation(): gr.Markdown("# MCQ Generation") with gr.Blocks() as mcq_generation: with gr.Tabs(): with gr.TabItem("POST"): post_interface() with gr.TabItem("GET"): get_interface() return mcq_generation