stibiumghost commited on
Commit
801e531
Β·
1 Parent(s): 7c17b3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -6,7 +6,7 @@ from text_gen import generate_text
6
 
7
  def get_answer(question, answer, options):
8
  '''File given answer'''
9
-
10
  global questions
11
  global SEPARATOR
12
  answer = options.split(SEPARATOR)[answer]
@@ -15,7 +15,7 @@ def get_answer(question, answer, options):
15
 
16
  def find_score(column_name, questions):
17
  '''Count chosen answers in a given column'''
18
-
19
  actual = questions[column_name].to_list()
20
  chosen = questions.Choice.to_list()
21
  return sum(a == c for a, c in zip(actual, chosen))
@@ -23,7 +23,7 @@ def find_score(column_name, questions):
23
 
24
  def set_score():
25
  '''Return the score (for the human and for the models)'''
26
-
27
  global NUM_QUESTIONS
28
  score = find_score(answers[0], questions)
29
  ai_score = {name:find_score(name, questions) for name in answers[1:]}
@@ -31,16 +31,33 @@ def set_score():
31
  start = '## <p style="text-align: center;">'
32
  end = '</p>'
33
 
34
- if score == NUM_QUESTIONS: text = f'Perfect score!'
 
35
  else:
36
- if score == 0: text = 'Not a single right answer. Are you doing this on purpose?'
37
- elif score <= NUM_QUESTIONS / 2 + 1: text = f'Only {score} right answers out of {NUM_QUESTIONS}. You ought to pay more attention.'
38
- else: text = f'{score} right answers out of {NUM_QUESTIONS}. It\'s probably alright.'
 
 
 
 
39
  for name in ai_score.keys():
40
  text += f'\n{name} got {ai_score[name]}.'
41
 
 
 
 
 
 
 
 
 
 
 
 
42
  return start + text + end
43
 
 
44
  if __name__ == "__main__":
45
 
46
  NUM_QUESTIONS = 10
@@ -48,8 +65,8 @@ if __name__ == "__main__":
48
 
49
 
50
  # Adding/replacing models may require adjustments to text_gen.py
51
- model_names = ['microsoft/GODEL-v1_1-base-seq2seq',
52
- 'facebook/blenderbot-400M-distill',
53
  'facebook/blenderbot_small-90M']
54
 
55
  tokenizers = [transformers.AutoTokenizer.from_pretrained(model_names[0]),
 
6
 
7
  def get_answer(question, answer, options):
8
  '''File given answer'''
9
+
10
  global questions
11
  global SEPARATOR
12
  answer = options.split(SEPARATOR)[answer]
 
15
 
16
  def find_score(column_name, questions):
17
  '''Count chosen answers in a given column'''
18
+ #global questions
19
  actual = questions[column_name].to_list()
20
  chosen = questions.Choice.to_list()
21
  return sum(a == c for a, c in zip(actual, chosen))
 
23
 
24
  def set_score():
25
  '''Return the score (for the human and for the models)'''
26
+
27
  global NUM_QUESTIONS
28
  score = find_score(answers[0], questions)
29
  ai_score = {name:find_score(name, questions) for name in answers[1:]}
 
31
  start = '## <p style="text-align: center;">'
32
  end = '</p>'
33
 
34
+ if score == NUM_QUESTIONS:
35
+ text = f'Perfect score!'
36
  else:
37
+ if score == 0:
38
+ text = 'Not a single right answer. Are you doing this on purpose?'
39
+ elif score <= NUM_QUESTIONS / 2 + 1:
40
+ text = f'Only {score} right answers out of {NUM_QUESTIONS}. You ought to pay more attention.'
41
+ else:
42
+ text = f'{score} right answers out of {NUM_QUESTIONS}. It\'s probably alright.'
43
+
44
  for name in ai_score.keys():
45
  text += f'\n{name} got {ai_score[name]}.'
46
 
47
+ # Add a section to display correct/incorrect answers
48
+ text += "\n\nList of questions with correct answers:\n"
49
+ i = 0
50
+ for idx, row in questions.iterrows():
51
+ i += 1
52
+ question = row['Question']
53
+ answer = row['Answer']
54
+ chosen_answer = row['Choice']
55
+ status = "βœ…" if answer == chosen_answer else "❌"
56
+ text += f"\n\n{status} {i}. {question} (Correct: {answer})\n"
57
+
58
  return start + text + end
59
 
60
+
61
  if __name__ == "__main__":
62
 
63
  NUM_QUESTIONS = 10
 
65
 
66
 
67
  # Adding/replacing models may require adjustments to text_gen.py
68
+ model_names = ['microsoft/GODEL-v1_1-large-seq2seq',
69
+ 'facebook/blenderbot-1B-distill',
70
  'facebook/blenderbot_small-90M']
71
 
72
  tokenizers = [transformers.AutoTokenizer.from_pretrained(model_names[0]),