BilalSardar commited on
Commit
3d68af8
1 Parent(s): a394b00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -31,9 +31,29 @@ import string
31
  import pke
32
  import traceback
33
  import spacy
 
34
 
 
 
 
35
 
36
- warnings.filterwarnings("ignore")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  def Process_audio(fileName):
38
  text=''
39
  txtf=open("The_audio.txt","w+")
@@ -72,14 +92,6 @@ def UrlToAudio(VideoUrl):
72
  Process_audio(str(wav_file_path))
73
  break
74
 
75
-
76
- summary_model = T5ForConditionalGeneration.from_pretrained('t5-base')
77
- summary_tokenizer = T5Tokenizer.from_pretrained('t5-base')
78
-
79
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
80
- summary_model = summary_model.to(device)
81
-
82
-
83
  def set_seed(seed: int):
84
  random.seed(seed)
85
  np.random.seed(seed)
@@ -92,8 +104,6 @@ def postprocesstext (content):
92
  sent = sent.capitalize()
93
  final = final +" "+sent
94
  return final
95
-
96
-
97
  def summarizer(text,model,tokenizer):
98
  text = text.strip().replace("\n"," ")
99
  text = "summarize: "+text
@@ -173,9 +183,7 @@ def get_keywords(originaltext,summarytext):
173
 
174
  return important_keywords[:4]
175
 
176
- question_model = T5ForConditionalGeneration.from_pretrained('ramsrigouthamg/t5_squad_v1')
177
- question_tokenizer = T5Tokenizer.from_pretrained('ramsrigouthamg/t5_squad_v1')
178
- question_model = question_model.to(device)
179
 
180
  def get_question(context,answer,model,tokenizer):
181
  text = "context: {} answer: {}".format(context,answer)
@@ -222,11 +230,7 @@ def get_distractors_wordnet(word):
222
  print ("Wordnet distractors not found")
223
  return distractors
224
 
225
- glove_file = 'glove.6B.300d.txt'
226
- tmp_file = 'word2vec-glove.6B.300d.txt'
227
 
228
- glove2word2vec(glove_file, tmp_file)
229
- model = KeyedVectors.load_word2vec_format(tmp_file)
230
  def generate_distractors(answer, count):
231
  answer = str.lower(answer)
232
 
@@ -284,7 +288,6 @@ def generate_question(context1,radiobutton):
284
  # return "Something Went Wrong...Please Check Link or try Again"
285
 
286
 
287
-
288
  iface = gr.Interface(
289
  fn=generate_question,
290
  inputs=[context1,radiobutton],
 
31
  import pke
32
  import traceback
33
  import spacy
34
+ warnings.filterwarnings("ignore")
35
 
36
+ ###############################################
37
+ # Models #
38
+ ###############################################
39
 
40
+ summary_model = T5ForConditionalGeneration.from_pretrained('t5-base')
41
+ summary_tokenizer = T5Tokenizer.from_pretrained('t5-base')
42
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
43
+ summary_model = summary_model.to(device)
44
+
45
+
46
+ glove_file = 'glove.6B.300d.txt'
47
+ tmp_file = 'word2vec-glove.6B.300d.txt'
48
+ glove2word2vec(glove_file, tmp_file)
49
+ model = KeyedVectors.load_word2vec_format(tmp_file)
50
+
51
+
52
+ question_model = T5ForConditionalGeneration.from_pretrained('ramsrigouthamg/t5_squad_v1')
53
+ question_tokenizer = T5Tokenizer.from_pretrained('ramsrigouthamg/t5_squad_v1')
54
+ question_model = question_model.to(device)
55
+
56
+ ###############################################
57
  def Process_audio(fileName):
58
  text=''
59
  txtf=open("The_audio.txt","w+")
 
92
  Process_audio(str(wav_file_path))
93
  break
94
 
 
 
 
 
 
 
 
 
95
  def set_seed(seed: int):
96
  random.seed(seed)
97
  np.random.seed(seed)
 
104
  sent = sent.capitalize()
105
  final = final +" "+sent
106
  return final
 
 
107
  def summarizer(text,model,tokenizer):
108
  text = text.strip().replace("\n"," ")
109
  text = "summarize: "+text
 
183
 
184
  return important_keywords[:4]
185
 
186
+
 
 
187
 
188
  def get_question(context,answer,model,tokenizer):
189
  text = "context: {} answer: {}".format(context,answer)
 
230
  print ("Wordnet distractors not found")
231
  return distractors
232
 
 
 
233
 
 
 
234
  def generate_distractors(answer, count):
235
  answer = str.lower(answer)
236
 
 
288
  # return "Something Went Wrong...Please Check Link or try Again"
289
 
290
 
 
291
  iface = gr.Interface(
292
  fn=generate_question,
293
  inputs=[context1,radiobutton],