Spaces:
Build error
Build error
BilalSardar
commited on
Commit
·
49e5bbb
1
Parent(s):
8b483be
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,10 @@ from pathlib import Path
|
|
4 |
from pydub import AudioSegment
|
5 |
from pydub.utils import make_chunks
|
6 |
import os
|
|
|
|
|
|
|
|
|
7 |
import torch
|
8 |
import warnings
|
9 |
import speech_recognition as sr
|
@@ -219,8 +223,25 @@ def get_distractors_wordnet(word):
|
|
219 |
print ("Wordnet distractors not found")
|
220 |
return distractors
|
221 |
|
222 |
-
|
|
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
context1 = gr.inputs.Textbox(lines=10, placeholder="Enter link here...")
|
225 |
output = gr.outputs.HTML( label="Question and Answers")
|
226 |
radiobutton = gr.inputs.Radio(["Wordnet", "Gensim"])
|
@@ -240,9 +261,9 @@ def generate_question(context1,radiobutton):
|
|
240 |
ques = get_question(summary_text,answer,question_model,question_tokenizer)
|
241 |
if radiobutton=="Wordnet":
|
242 |
distractors = get_distractors_wordnet(answer)
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
|
247 |
# output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
|
248 |
output ="\n"+ output + "<b style='color:blue;'>" + ques + "</b>"
|
|
|
4 |
from pydub import AudioSegment
|
5 |
from pydub.utils import make_chunks
|
6 |
import os
|
7 |
+
import gensim
|
8 |
+
from gensim.test.utils import datapath, get_tmpfile
|
9 |
+
from gensim.scripts.glove2word2vec import glove2word2vec
|
10 |
+
from gensim.models import KeyedVectors
|
11 |
import torch
|
12 |
import warnings
|
13 |
import speech_recognition as sr
|
|
|
223 |
print ("Wordnet distractors not found")
|
224 |
return distractors
|
225 |
|
226 |
+
glove_file = 'gdrive/My Drive/distractors/glove.6B.300d.txt'
|
227 |
+
tmp_file = 'gdrive/My Drive/distractors/word2vec-glove.6B.300d.txt'
|
228 |
|
229 |
+
glove2word2vec(glove_file, tmp_file)
|
230 |
+
model = KeyedVectors.load_word2vec_format(tmp_file)
|
231 |
+
def generate_distractors(answer, count):
|
232 |
+
answer = str.lower(answer)
|
233 |
+
|
234 |
+
##Extracting closest words for the answer.
|
235 |
+
try:
|
236 |
+
closestWords = model.most_similar(positive=[answer], topn=count)
|
237 |
+
except:
|
238 |
+
#In case the word is not in the vocabulary, or other problem not loading embeddings
|
239 |
+
return []
|
240 |
+
|
241 |
+
#Return count many distractors
|
242 |
+
distractors = list(map(lambda x: x[0], closestWords))[0:count]
|
243 |
+
|
244 |
+
return distractors
|
245 |
context1 = gr.inputs.Textbox(lines=10, placeholder="Enter link here...")
|
246 |
output = gr.outputs.HTML( label="Question and Answers")
|
247 |
radiobutton = gr.inputs.Radio(["Wordnet", "Gensim"])
|
|
|
261 |
ques = get_question(summary_text,answer,question_model,question_tokenizer)
|
262 |
if radiobutton=="Wordnet":
|
263 |
distractors = get_distractors_wordnet(answer)
|
264 |
+
else:
|
265 |
+
distractors = generate_distractors(answer.capitalize(),3)
|
266 |
+
print(distractors)
|
267 |
|
268 |
# output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
|
269 |
output ="\n"+ output + "<b style='color:blue;'>" + ques + "</b>"
|