import gradio as gr # Load the question generation model question_gen = gr.load("models/allenai/t5-small-squad2-question-generation") # Define a function to generate questions def generate_questions(text, num_questions=5): questions = [] for i in range(num_questions): output = question_gen.predict(text) questions.append(output["generated_text"]) return questions # Define the input and output interfaces input_text = gr.inputs.Textbox(label="Enter some text:") num_questions = gr.inputs.Number(default=5, label="Number of questions to generate:") output_text = gr.outputs.Textbox(label="Generated questions:") # Create the interface iface = gr.Interface( generate_questions, inputs=[input_text, num_questions], outputs=output_text, title="Question Generator", description="Generate questions from text using the T5-SQuAD2 model.", ) # Launch the interface iface.launch()