File size: 4,572 Bytes
93baaeb
 
 
 
 
 
1ba1758
93baaeb
 
 
7bbfec2
93baaeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import openai
import os
import gradio as gr
from mcq_func import *
from stack_func import *

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

counter = 1

def generate_output_name(input_text):
    global counter
    counter += 1
    return gr.Textbox.update(value=f"Question {counter}"+ input_text)


title = "Moodle Question Generator v0.2"

with gr.Blocks(title=title) as demo:
    gr.Markdown("""
    # AI Question Generator v0.2
    Generate Moodle/Inspera MCQ and STACK questions. Put your ideas for the questions in the question description section, then click Generate. A Moodle/Inspera file will be available for download.
    """)
    with gr.Tab("MCQ"):
       with gr.Row():
           with gr.Column():
             mcq_input1 = gr.Textbox(label="Question Description",
             info="Describe your MCQ question",
             lines=5,
             value="Replace with your idea on the question...",
             )
             mcq_input2 = gr.Number(label="Number of Question",
             info="Numerical value only",
             value=1,
             precision=0, 
             )
             mcq_button = gr.Button("Generate")
             gr.Examples(["Write a history question","Write a geology question"], inputs=[mcq_input1])
           with gr.Column():
             mcq_output1 = gr.Textbox(
             label="Question Preview",
             info="Question name, text and options",
             lines=5,
             value="Depending on question number and complexity, please wait up to 2 mins (~20s each)",
             )
             mcq_output2 = gr.File(
             label="Export",
             info="Use in Moodle"    
             )
    with gr.Tab("Inspera MCQ"):
       with gr.Row():
           with gr.Column():
             inspera_mcq_input1 = gr.Textbox(label="Question Description",
             info="Describe your MCQ question",
             lines=5,
             value="Replace with your idea on the question...",
             )
             inspera_mcq_input2 = gr.Number(label="Number of Question",
             info="Numerical value only",
             value=1,
             precision=0, 
             )
             inspera_mcq_button = gr.Button("Generate")
             gr.Examples(["Write a history question","Write a geology question"], inputs=[inspera_mcq_input1])
           with gr.Column():
             inspera_mcq_output1 = gr.Textbox(
             label="Question Preview",
             info="Question name, text and options",
             lines=5,
             value="Depending on question number and complexity, please wait up to 2 mins (~20s each)",
             )
             inspera_mcq_output2 = gr.File(
             label="Export",
             info="Use in Moodle"    
             )
    with gr.Tab("STACK"):
       with gr.Row():
           with gr.Column():
             stack_input = gr.Textbox(label="Question Description",
             info="Describe your STACK question",
             lines=5,
             value="Replace with your idea on the question...",
             )
             stack_button = gr.Button("Generate")
             gr.Examples(["Write a question on Ohm's Law","Write a question on a business topic","generate a STACK question about organising an event, with these random variables: number of people, cost of catering per people, one-off renting of venue. Answer: number of people * cost of catering per people + one-off rent.Provide a story and details in question text. For the second part of the question, ask what price should be for each people if prices are set at cost-recovery only. Answer would be the total cost from part one divided by number of people. Add a partial correct scenario when marking second part, where the cost is calculated using answer provided in part one"], inputs=[stack_input])
           with gr.Column():
             stack_output1 = gr.Textbox(
             label="Comment",
             info="Comment from GPT (if any):",
             lines=5,
             value="Depending on question complexity, please wait up to 5 mins",
             )
             stack_output2 = gr.File(
             label="Export",
             info="Use in Moodle"    
             )



    mcq_button.click(multi_mcq, inputs=[mcq_input1,mcq_input2], outputs=[mcq_output1,mcq_output2])        
    inspera_mcq_button.click(inspera_multi_mcq, inputs=[inspera_mcq_input1,inspera_mcq_input2], outputs=[inspera_mcq_output1,inspera_mcq_output2])
    stack_button.click(generate_stack, inputs=stack_input, outputs=[stack_output1,stack_output2])

demo.queue().launch()