Pranjal12345 commited on
Commit
83923d6
·
1 Parent(s): 9e3d219

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spacy
3
+ from lmqg import TransformersQG
4
+
5
+ spacy.cli.download("en_core_web_sm")
6
+
7
+ model = TransformersQG(model='lmqg/t5-base-squad-qg', model_ae='lmqg/t5-base-squad-ae')
8
+
9
+ def generate_questions(text):
10
+ result = []
11
+ final_result = []
12
+ max_length = 2000
13
+
14
+ while len(text) > max_length:
15
+ chunk = text[:max_length]
16
+ last_period_index = chunk.rfind('.')
17
+
18
+ if last_period_index != -1:
19
+ result.append(chunk[:last_period_index + 1])
20
+ text = text[last_period_index + 1:]
21
+ else:
22
+ result.append(chunk)
23
+ text = text[max_length:]
24
+
25
+ for i in result:
26
+ question_answer = model.generate_qa(i)
27
+ for j in range(len(question_answer):
28
+ question = question_answer[j][0]
29
+ final_result.append(question)
30
+
31
+ return final_result
32
+
33
+ interface = gr.Interface(fn=generate_questions, inputs="text", outputs="text")
34
+ interface.launch()