BilalSardar commited on
Commit
9ab118d
1 Parent(s): 50a201b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -33
app.py CHANGED
@@ -247,39 +247,43 @@ output = gr.outputs.HTML( label="Question and Answers")
247
  radiobutton = gr.inputs.Radio(["Wordnet", "Gensim"])
248
 
249
  def generate_question(context1,radiobutton):
250
- UrlToAudio(context1)
251
- f = open("The_audio.txt", "r")
252
- context=f.read()
253
- summary_text = summarizer(context,summary_model,summary_tokenizer)
254
- for wrp in wrap(summary_text, 150):
255
- print (wrp)
256
- # np = getnounphrases(summary_text,sentence_transformer_model,3)
257
- np = get_keywords(context,summary_text)
258
- print ("\n\nNoun phrases",np)
259
- output=""
260
- for answer in np:
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>"
270
- # output = output + "<br>"
271
- output ="\n"+ output + "<b style='color:green;'>" + "Ans: " +answer.capitalize()+ "</b>"
272
- if len(distractors)>0:
273
- for distractor in distractors[:4]:
274
- output = output + " <b style='color:brown;'>" + distractor+ "</b>\n"
275
- output = output + "<br>"
276
-
277
- summary ="Summary: "+ summary_text
278
- for answer in np:
279
- summary = summary.replace(answer,"<b>"+answer+"</b>")
280
- summary = summary.replace(answer.capitalize(),"<b>"+answer.capitalize()+"</b>")
281
- output = output + "<p>"+summary+"</p>"
282
- return output
 
 
 
 
283
 
284
 
285
  iface = gr.Interface(
 
247
  radiobutton = gr.inputs.Radio(["Wordnet", "Gensim"])
248
 
249
  def generate_question(context1,radiobutton):
250
+ try:
251
+ UrlToAudio(context1)
252
+ f = open("The_audio.txt", "r")
253
+ context=f.read()
254
+ summary_text = summarizer(context,summary_model,summary_tokenizer)
255
+ for wrp in wrap(summary_text, 150):
256
+ print (wrp)
257
+ # np = getnounphrases(summary_text,sentence_transformer_model,3)
258
+ np = get_keywords(context,summary_text)
259
+ print ("\n\nNoun phrases",np)
260
+ output=""
261
+ for answer in np:
262
+ ques = get_question(summary_text,answer,question_model,question_tokenizer)
263
+ if radiobutton=="Wordnet":
264
+ distractors = get_distractors_wordnet(answer)
265
+ else:
266
+ distractors = generate_distractors(answer.capitalize(),3)
267
+ print(distractors)
268
+
269
+ # output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
270
+ output ="\n"+ output + "<b style='color:blue;'>" + ques + "</b>"
271
+ # output = output + "<br>"
272
+ output ="\n"+ output + "<b style='color:green;'>" + "Ans: " +answer.capitalize()+ "</b>"
273
+ if len(distractors)>0:
274
+ for distractor in distractors[:4]:
275
+ output = output + " <b style='color:brown;'>" + distractor+ "</b>\n"
276
+ output = output + "<br>"
277
+
278
+ summary ="Summary: "+ summary_text
279
+ for answer in np:
280
+ summary = summary.replace(answer,"<b>"+answer+"</b>")
281
+ summary = summary.replace(answer.capitalize(),"<b>"+answer.capitalize()+"</b>")
282
+ output = output + "<p>"+summary+"</p>"
283
+ return output
284
+ except:
285
+ return "Something Went Wrong...Please Check Link or try Again"
286
+
287
 
288
 
289
  iface = gr.Interface(