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()