JRQi commited on
Commit
8a63757
β€’
1 Parent(s): fde583d

Update game3.py

Browse files
Files changed (1) hide show
  1. game3.py +23 -94
game3.py CHANGED
@@ -39,7 +39,10 @@ def func3(num_selected, human_predict, num1, num2, user_important):
39
  interpretation = eval(content[int(num_selected*2+1)])
40
 
41
  golden_label = (text['binary_label']^1) * 100
42
-
 
 
 
43
  # (START) off-the-shelf version -- slow at the beginning
44
  # Load model directly
45
  # Use a pipeline as a high-level helper
@@ -47,13 +50,6 @@ def func3(num_selected, human_predict, num1, num2, user_important):
47
  classifier = pipeline("text-classification", model="padmajabfrl/Gender-Classification")
48
  output = classifier([text['text']])
49
 
50
- # star2num = {
51
- # "5 stars": 100,
52
- # "4 stars": 75,
53
- # "3 stars": 50,
54
- # "2 stars": 25,
55
- # "1 star": 0,
56
- # }
57
  print(output)
58
  out = output[0]
59
 
@@ -80,102 +76,35 @@ def func3(num_selected, human_predict, num1, num2, user_important):
80
  # if not flag_select:
81
  # user_select += "nothing. Interesting! "
82
  user_select += "Wanna see how the AI made the guess? Click here. ⬅️"
83
- if lang_selected in ['en']:
84
- if ai_predict == golden_label:
85
- if abs(human_predict - golden_label) < 12.5: # Both correct
86
- golden_label = int((human_predict + ai_predict) / 2)
87
- chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
88
- num1 += 1
89
- num2 += 1
90
- else:
91
- golden_label += random.randint(-2, 2)
92
- while golden_label > 100 or golden_label < 0 or golden_label % 25 == 0:
93
- golden_label += random.randint(-2, 2)
94
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
95
- num2 += 1
96
  else:
97
- if abs(human_predict - golden_label) < abs(ai_predict - golden_label):
98
- if abs(human_predict - golden_label) < 12.5:
99
- golden_label = int((golden_label + human_predict) / 2)
100
- chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are closer to the answer and better than AI!", user_select))
101
- num1 += 1
102
- else:
103
- chatbot.append(("The correct answer is " + str(golden_label) + ". Both wrong... Maybe next time you'll win!", user_select))
104
- else:
105
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! πŸ˜‰", user_select))
106
  else:
107
- if golden_label == 100:
108
- if ai_predict > 50 and human_predict > 50:
109
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
110
- while golden_label > 100:
111
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
112
- ai_predict = int((golden_label + ai_predict) / 2)
113
- chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
114
- num1 += 1
115
- num2 += 1
116
- elif ai_predict > 50 and human_predict <= 50:
117
- golden_label -= random.randint(0, 10)
118
- ai_predict = 90 + random.randint(-5, 5)
119
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
120
- num2 += 1
121
- elif ai_predict <= 50 and human_predict > 50:
122
- golden_label = human_predict + random.randint(-4, 4)
123
- while golden_label > 100:
124
- golden_label = human_predict + random.randint(-4, 4)
125
- chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are close to the answer and better than AI!", user_select))
126
  num1 += 1
127
  else:
128
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry... No one gets the correct answer. But nice try! πŸ˜‰", user_select))
129
  else:
130
- if ai_predict < 50 and human_predict < 50:
131
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
132
- while golden_label < 0:
133
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
134
- ai_predict = int((golden_label + ai_predict) / 2)
135
- chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
136
- num1 += 1
137
- num2 += 1
138
- elif ai_predict < 50 and human_predict >= 50:
139
- golden_label += random.randint(0, 10)
140
- ai_predict = 10 + random.randint(-5, 5)
141
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
142
- num2 += 1
143
- elif ai_predict >= 50 and human_predict < 50:
144
- golden_label = human_predict + random.randint(-4, 4)
145
- while golden_label < 0:
146
- golden_label = human_predict + random.randint(-4, 4)
147
- chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are close to the answer and better than AI!", user_select))
148
- num1 += 1
149
- else:
150
- chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry... No one gets the correct answer. But nice try! πŸ˜‰", user_select))
151
-
152
- # data = pd.DataFrame(
153
- # {
154
- # "Role": ["AI πŸ€–", "HUMAN πŸ‘¨πŸ‘©"],
155
- # "Scores": [num2, num1],
156
- # }
157
- # )
158
- # scroe_human = ''' # Human: ''' + str(int(num1))
159
- # scroe_robot = ''' # Robot: ''' + str(int(num2))
160
  tot_scores = ''' ### <p style="text-align: center;"> Machine &ensp; ''' + str(int(num2)) + ''' &ensp; VS &ensp; ''' + str(int(num1)) + ''' &ensp; Human </p>'''
161
 
162
 
163
  num_tmp = max(num1, num2)
164
  y_lim_upper = (int((num_tmp + 3)/10)+1) * 10
165
- # figure = gr.BarPlot.update(
166
- # data,
167
- # x="Role",
168
- # y="Scores",
169
- # color="Role",
170
- # vertical=False,
171
- # y_lim=[0,y_lim_upper],
172
- # color_legend_position='none',
173
- # height=250,
174
- # width=500,
175
- # show_label=False,
176
- # container=False,
177
- # )
178
- # tooltip=["Role", "Scores"],
179
  return ai_predict, chatbot, num1, num2, tot_scores
180
 
181
  def interpre3(lang_selected, num_selected):
 
39
  interpretation = eval(content[int(num_selected*2+1)])
40
 
41
  golden_label = (text['binary_label']^1) * 100
42
+ if golden_label == 0:
43
+ golden_label = 50 * (1 - text['binary_score'])
44
+ else:
45
+ golden_label = 50 * (1 + text['binary_score'])
46
  # (START) off-the-shelf version -- slow at the beginning
47
  # Load model directly
48
  # Use a pipeline as a high-level helper
 
50
  classifier = pipeline("text-classification", model="padmajabfrl/Gender-Classification")
51
  output = classifier([text['text']])
52
 
 
 
 
 
 
 
 
53
  print(output)
54
  out = output[0]
55
 
 
76
  # if not flag_select:
77
  # user_select += "nothing. Interesting! "
78
  user_select += "Wanna see how the AI made the guess? Click here. ⬅️"
79
+ if abs(ai_predict - golden_label) < 12.5:
80
+ if abs(human_predict - golden_label) < 12.5: # Both correct
81
+ golden_label = int((human_predict + ai_predict) / 2)
82
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
83
+ num1 += 1
84
+ num2 += 1
 
 
 
 
 
 
 
85
  else:
86
+ golden_label += random.randint(-2, 2)
87
+ while golden_label > 100 or golden_label < 0 or golden_label % 25 == 0:
88
+ golden_label += random.randint(-2, 2)
89
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
90
+ num2 += 1
 
 
 
 
91
  else:
92
+ if abs(human_predict - golden_label) < abs(ai_predict - golden_label):
93
+ if abs(human_predict - golden_label) < 12.5:
94
+ golden_label = int((golden_label + human_predict) / 2)
95
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are closer to the answer and better than AI!", user_select))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  num1 += 1
97
  else:
98
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Both wrong... Maybe next time you'll win!", user_select))
99
  else:
100
+ chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! πŸ˜‰", user_select))
101
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  tot_scores = ''' ### <p style="text-align: center;"> Machine &ensp; ''' + str(int(num2)) + ''' &ensp; VS &ensp; ''' + str(int(num1)) + ''' &ensp; Human </p>'''
103
 
104
 
105
  num_tmp = max(num1, num2)
106
  y_lim_upper = (int((num_tmp + 3)/10)+1) * 10
107
+
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  return ai_predict, chatbot, num1, num2, tot_scores
109
 
110
  def interpre3(lang_selected, num_selected):