import gradio as gr import spacy from lmqg import TransformersQG spacy.cli.download("en_core_web_sm") model = TransformersQG(model='lmqg/t5-base-squad-qg', model_ae='lmqg/t5-base-squad-ae') def generate_questions(text): result = [] final_result = [] max_length = 2000 while len(text) > max_length: chunk = text[:max_length] last_period_index = chunk.rfind('.') if last_period_index != -1: result.append(chunk[:last_period_index + 1]) text = text[last_period_index + 1:] else: result.append(chunk) text = text[max_length:] for i in result: question_answer = model.generate_qa(i) for j in range(len(question_answer)): question = question_answer[j][0] final_result.append(question) return final_result interface = gr.Interface(fn=generate_questions, inputs="text", outputs="text") interface.launch()