|
import gradio as gr |
|
from backend import get_question |
|
|
|
|
|
def generate(context, qtype, difficulty, num): |
|
try: |
|
|
|
return "\n\n".join(get_question(qtype, difficulty, context, "", num)) |
|
except Exception as e: |
|
return f"Error: {str(e)}" |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Finetuned T5Base Question Generator [Descriptive, MCQ, T/F]") |
|
|
|
with gr.Row(): |
|
context = gr.Textbox(label="Context", lines=8, placeholder="Paste your context here...") |
|
|
|
with gr.Row(): |
|
qtype = gr.Dropdown(["short answer", "multiple choice question", "true or false question"], label="Question Type") |
|
difficulty = gr.Dropdown(["easy", "medium", "hard"], label="Difficulty") |
|
num = gr.Slider(1, 5, step=1, label="Number of Questions", value=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with gr.Row(): |
|
btn = gr.Button("Generate Questions") |
|
|
|
output = gr.Textbox(label="Generated Questions", lines=10) |
|
|
|
|
|
btn.click(fn=generate, inputs=[context, qtype, difficulty, num], outputs=output) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|