Technozam commited on
Commit
2b7d36e
1 Parent(s): b9d20a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -21
app.py CHANGED
@@ -377,36 +377,57 @@ def generate_question_text(context,subject,total):
377
  elif (words_subject < 1):
378
  raise gr.Error("Invalid Input (Title must be one or more than one word).")
379
 
380
- else:
381
  summary_text = summarizer(context,summary_model,summary_tokenizer)
382
  for wrp in wrap(summary_text, 150):
383
  print (wrp)
384
  # np = getnounphrases(summary_text,sentence_transformer_model,3)
385
  np = get_keywords(context,summary_text,total)
 
386
  print ("\n\nNoun phrases",np)
387
 
388
- output="<b style='color:black;'>Select the correct answer.</b><br><br>"
389
  i = 1
390
  for answer in np:
391
  ques = get_question(summary_text,answer,question_model,question_tokenizer)
 
392
  distractors = get_distractors(answer.capitalize(),ques,s2v,sentence_transformer_model,40,0.2)
393
  # output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
394
- output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b>"
395
  # output = output + "<br>"
396
  i += 1
397
- output = output + "<br><b> ▪ " +answer.capitalize()+ "</b>"
398
- if len(distractors)>0:
399
- for distractor in distractors[:3]:
400
- output = output + "<p> ▪ " + distractor+ "</p>"
401
- output = output + "<br>"
402
 
403
- output = output + "<b style='color:black;'>" + "Correct Answer Key</b><br>"
 
 
 
 
 
 
 
 
 
 
 
 
404
 
405
  i = 1
406
  for answer in np:
407
- i += 1
408
- output = output + "<b style='color:green;'> ▪ " +answer.capitalize()+ "</b>"
409
  output = output + "<br>"
 
 
 
 
 
 
 
 
 
 
 
 
 
410
 
411
  return output
412
 
@@ -425,30 +446,52 @@ def generate_question(context,subject,total):
425
  print (wrp)
426
  # np = getnounphrases(summary_text,sentence_transformer_model,3)
427
  np = get_keywords(context,summary_text,total)
 
 
428
  print ("\n\nNoun phrases",np)
429
 
430
- output="<b style='color:black;'>Select the correct answer.</b><br><br>"
431
  i = 1
432
  for answer in np:
433
  ques = get_question(summary_text,answer,question_model,question_tokenizer)
 
434
  distractors = get_distractors(answer.capitalize(),ques,s2v,sentence_transformer_model,40,0.2)
435
  # output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
436
- output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b>"
437
  # output = output + "<br>"
438
  i += 1
439
- output = output + "<br><b> ▪ " +answer.capitalize()+ "</b>"
440
- if len(distractors)>0:
441
- for distractor in distractors[:3]:
442
- output = output + "<p> ▪ " + distractor+ "</p>"
443
- output = output + "<br>"
444
 
445
- output = output + "<b style='color:black;'>" + "Correct Answer Key</b><br>"
 
 
 
 
 
 
 
 
 
 
 
 
446
 
447
  i = 1
448
  for answer in np:
 
 
449
  i += 1
450
- output = output + "<b style='color:green;'> ▪ " +answer.capitalize()+ "</b>"
451
- output = output + "<br>"
 
 
 
 
 
 
 
 
 
 
452
 
453
  return output
454
 
 
377
  elif (words_subject < 1):
378
  raise gr.Error("Invalid Input (Title must be one or more than one word).")
379
 
380
+ else:
381
  summary_text = summarizer(context,summary_model,summary_tokenizer)
382
  for wrp in wrap(summary_text, 150):
383
  print (wrp)
384
  # np = getnounphrases(summary_text,sentence_transformer_model,3)
385
  np = get_keywords(context,summary_text,total)
386
+ random.shuffle(np)
387
  print ("\n\nNoun phrases",np)
388
 
389
+ output="<b style='color:black;'>Select/Tick the correct answer.</b><br><br>"
390
  i = 1
391
  for answer in np:
392
  ques = get_question(summary_text,answer,question_model,question_tokenizer)
393
+
394
  distractors = get_distractors(answer.capitalize(),ques,s2v,sentence_transformer_model,40,0.2)
395
  # output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
396
+ output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b><br/>"
397
  # output = output + "<br>"
398
  i += 1
 
 
 
 
 
399
 
400
+ answerlist=[answer.capitalize()]
401
+
402
+ # output = output + "<br><b> ▪ " +answer.capitalize()+ "</b>"
403
+ for distractor in distractors[:3]:
404
+ answerlist.append(distractor)
405
+ random.shuffle(answerlist)
406
+
407
+ print(answerlist)
408
+
409
+ for answer in answerlist:
410
+ output = output +answer.capitalize()+ "<br/>"
411
+
412
+ output = output + "<br><b style='color:black;'>" + "Correct Answer Key:</b><br>"
413
 
414
  i = 1
415
  for answer in np:
416
+ output = output + "<b style='color:green;'>Ans"+ str(i) + ") " +answer.capitalize()+ "</b>"
 
417
  output = output + "<br>"
418
+ i += 1
419
+
420
+
421
+ # mycursor = mydb.cursor()
422
+ # timedate = datetime.datetime.now()
423
+
424
+ # sql = "INSERT INTO mcqstexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
425
+ # val = (subject, context, output, timedate)
426
+ # mycursor.execute(sql, val)
427
+
428
+ # mydb.commit()
429
+
430
+ # print(mycursor.rowcount, "record inserted.")
431
 
432
  return output
433
 
 
446
  print (wrp)
447
  # np = getnounphrases(summary_text,sentence_transformer_model,3)
448
  np = get_keywords(context,summary_text,total)
449
+ random.shuffle(np)
450
+
451
  print ("\n\nNoun phrases",np)
452
 
453
+ output="<b style='color:black;'>Select/Tick the correct answer.</b><br><br>"
454
  i = 1
455
  for answer in np:
456
  ques = get_question(summary_text,answer,question_model,question_tokenizer)
457
+
458
  distractors = get_distractors(answer.capitalize(),ques,s2v,sentence_transformer_model,40,0.2)
459
  # output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
460
+ output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b><br/>"
461
  # output = output + "<br>"
462
  i += 1
 
 
 
 
 
463
 
464
+ answerlist=[answer.capitalize()]
465
+
466
+ # output = output + "<br><b> ▪ " +answer.capitalize()+ "</b>"
467
+ for distractor in distractors[:3]:
468
+ answerlist.append(distractor)
469
+ random.shuffle(answerlist)
470
+
471
+ # print(answerlist)
472
+
473
+ for answer in answerlist:
474
+ output = output +answer.capitalize()+ "<br/>"
475
+
476
+ output = output + "<br><b style='color:black;'>" + "Correct Answer Key:</b><br>"
477
 
478
  i = 1
479
  for answer in np:
480
+ output = output + "<b style='color:green;'>Ans"+ str(i) + ") " +answer.capitalize()+ "</b>"
481
+ output = output + "<br/>"
482
  i += 1
483
+
484
+
485
+ # mycursor = mydb.cursor()
486
+ # timedate = datetime.datetime.now()
487
+
488
+ # sql = "INSERT INTO mcqstexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
489
+ # val = (subject, context, output, timedate)
490
+ # mycursor.execute(sql, val)
491
+
492
+ # mydb.commit()
493
+
494
+ # print(mycursor.rowcount, "record inserted.")
495
 
496
  return output
497