File size: 960 Bytes
83923d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a42240
83923d6
 
 
 
 
 
 
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
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()