QL2023's picture
Update app.py
7bbfec2
Raw History Blame Contribute Delete
4.57 kB
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()