File size: 1,851 Bytes
62f90c5 eba6de6 62f90c5 55e9bbe 62f90c5 55e9bbe 62f90c5 0261a9b 62f90c5 0261a9b 62f90c5 f6a8d01 62f90c5 2317c8f 55e9bbe 694a396 0b8a022 694a396 2317c8f 55e9bbe 62f90c5 55e9bbe 62f90c5 |
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 |
import gradio as gr
from backend import get_question
# def generate(context, qtype, difficulty, num, use_beam_search, num_beams): -----------------------
def generate(context, qtype, difficulty, num):
try:
# return "\n\n".join(get_question(qtype, difficulty, context, "", num, use_beam_search=use_beam_search, num_beams=num_beams)) -------------
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(visible=True) as beam_controls:--------------------------------------
# use_beam = gr.Checkbox(label="Use Beam Search", value=False)
# beam_dropdown = gr.Dropdown(choices=[3, 4, 5, 6], value=3, label="Number of Beams")
# def toggle_beam_controls(n):
# return gr.update(visible=(n == 1))
# num.change(fn=toggle_beam_controls, inputs=num, outputs=beam_controls) -------------------------------
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, use_beam, beam_dropdown], outputs=output)
btn.click(fn=generate, inputs=[context, qtype, difficulty, num], outputs=output)
if __name__ == "__main__":
demo.launch()
|