JRQi commited on
Commit
6e9f2fe
β€’
1 Parent(s): add688f

Update game1.py

Browse files
Files changed (1) hide show
  1. game1.py +57 -42
game1.py CHANGED
@@ -77,9 +77,9 @@ def func1(lang_selected, num_selected, human_predict, num1, num2, user_important
77
  text = eval(content[int(num_selected*2)])
78
  interpretation = eval(content[int(num_selected*2+1)])
79
  if lang_selected in ['en']:
80
- golden_label = text['label'] * 25
81
  else:
82
- golden_label = text['label'] * 100
83
 
84
  '''
85
  # (START) API version -- quick
@@ -121,10 +121,10 @@ def func1(lang_selected, num_selected, human_predict, num1, num2, user_important
121
  output = classifier([text['text']])
122
 
123
  star2num = {
124
- "5 stars": 100,
125
- "4 stars": 75,
126
- "3 stars": 50,
127
- "2 stars": 25,
128
  "1 star": 0,
129
  }
130
  print(output)
@@ -153,72 +153,86 @@ def func1(lang_selected, num_selected, human_predict, num1, num2, user_important
153
  # user_select += "nothing. Interesting! "
154
  user_select += "Wanna see how the AI made the guess? Click here. ⬅️"
155
  if lang_selected in ['en']:
 
156
  if ai_predict == golden_label:
157
- if abs(human_predict - golden_label) < 12.5: # Both correct
158
  golden_label = int((human_predict + ai_predict) / 2)
 
159
  chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
160
  num1 += 1
161
  num2 += 1
162
  else:
163
- golden_label += random.randint(-2, 2)
164
- while golden_label > 100 or golden_label < 0 or golden_label % 25 == 0:
165
- golden_label += random.randint(-2, 2)
 
166
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
167
  num2 += 1
168
  else:
169
  if abs(human_predict - golden_label) < abs(ai_predict - golden_label):
170
- if abs(human_predict - golden_label) < 12.5:
171
  golden_label = int((golden_label + human_predict) / 2)
 
172
  chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are closer to the answer and better than AI!", user_select))
173
  num1 += 1
174
  else:
 
 
175
  chatbot.append(("The correct answer is " + str(golden_label) + ". Both wrong... Maybe next time you'll win!", user_select))
176
  else:
 
 
177
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! πŸ˜‰", user_select))
178
  else:
179
- if golden_label == 100:
180
- if ai_predict > 50 and human_predict > 50:
181
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
182
- while golden_label > 100:
183
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
184
  ai_predict = int((golden_label + ai_predict) / 2)
185
  chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
186
  num1 += 1
187
  num2 += 1
188
- elif ai_predict > 50 and human_predict <= 50:
189
- golden_label -= random.randint(0, 10)
190
- ai_predict = 90 + random.randint(-5, 5)
191
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
192
  num2 += 1
193
- elif ai_predict <= 50 and human_predict > 50:
194
- golden_label = human_predict + random.randint(-4, 4)
195
- while golden_label > 100:
196
- golden_label = human_predict + random.randint(-4, 4)
 
197
  chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are close to the answer and better than AI!", user_select))
198
  num1 += 1
199
  else:
 
 
200
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry... No one gets the correct answer. But nice try! πŸ˜‰", user_select))
201
  else:
202
- if ai_predict < 50 and human_predict < 50:
203
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
204
  while golden_label < 0:
205
- golden_label = int((human_predict + ai_predict)/2) + random.randint(-10, 10)
206
  ai_predict = int((golden_label + ai_predict) / 2)
207
  chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
208
  num1 += 1
209
  num2 += 1
210
- elif ai_predict < 50 and human_predict >= 50:
211
- golden_label += random.randint(0, 10)
212
- ai_predict = 10 + random.randint(-5, 5)
213
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
214
  num2 += 1
215
- elif ai_predict >= 50 and human_predict < 50:
216
- golden_label = human_predict + random.randint(-4, 4)
217
  while golden_label < 0:
218
- golden_label = human_predict + random.randint(-4, 4)
 
219
  chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are close to the answer and better than AI!", user_select))
220
  num1 += 1
221
  else:
 
 
222
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry... No one gets the correct answer. But nice try! πŸ˜‰", user_select))
223
 
224
  # data = pd.DataFrame(
@@ -232,8 +246,8 @@ def func1(lang_selected, num_selected, human_predict, num1, num2, user_important
232
  tot_scores = ''' ### <p style="text-align: center;"> πŸ€– Machine &ensp; ''' + str(int(num2)) + ''' &ensp; VS &ensp; ''' + str(int(num1)) + ''' &ensp; Human πŸ‘¨πŸ‘© </p>'''
233
 
234
 
235
- num_tmp = max(num1, num2)
236
- y_lim_upper = (int((num_tmp + 3)/10)+1) * 10
237
  # figure = gr.BarPlot.update(
238
  # data,
239
  # x="Role",
@@ -331,10 +345,10 @@ def func1_written(text_written, human_predict, lang_written):
331
  output = classifier([text_written])
332
 
333
  star2num = {
334
- "5 stars": 100,
335
- "4 stars": 75,
336
- "3 stars": 50,
337
- "2 stars": 25,
338
  "1 star": 0,
339
  }
340
  print(output)
@@ -345,12 +359,13 @@ def func1_written(text_written, human_predict, lang_written):
345
  ai_predict = star2num[out['label']]
346
  # result[label] = out['score']
347
 
348
- if abs(ai_predict - human_predict) <= 12.5:
 
349
  chatbot.append(("AI gives it a close score! πŸŽ‰", "⬅️ Feel free to try another one! ⬅️"))
350
  else:
351
- ai_predict += random.randint(-2, 2)
352
- while ai_predict > 100 or ai_predict < 0 or ai_predict % 25 == 0:
353
- ai_predict += random.randint(-2, 2)
354
  chatbot.append(("AI thinks in a different way from human. πŸ˜‰", "⬅️ Feel free to try another one! ⬅️"))
355
 
356
 
 
77
  text = eval(content[int(num_selected*2)])
78
  interpretation = eval(content[int(num_selected*2+1)])
79
  if lang_selected in ['en']:
80
+ golden_label = text['label'] * 2.5
81
  else:
82
+ golden_label = text['label'] * 10
83
 
84
  '''
85
  # (START) API version -- quick
 
121
  output = classifier([text['text']])
122
 
123
  star2num = {
124
+ "5 stars": 10,
125
+ "4 stars": 7.5,
126
+ "3 stars": 5,
127
+ "2 stars": 2.5,
128
  "1 star": 0,
129
  }
130
  print(output)
 
153
  # user_select += "nothing. Interesting! "
154
  user_select += "Wanna see how the AI made the guess? Click here. ⬅️"
155
  if lang_selected in ['en']:
156
+ # 0 1 2 3 4 5 6 7 8 9 10
157
  if ai_predict == golden_label:
158
+ if abs(human_predict - golden_label) < 2: # Both correct
159
  golden_label = int((human_predict + ai_predict) / 2)
160
+ ai_predict = golden_label
161
  chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
162
  num1 += 1
163
  num2 += 1
164
  else:
165
+ golden_label += int(random.randint(-1, 1) * 0.5)
166
+ while golden_label > 10 or golden_label < 0:
167
+ golden_label += int(random.randint(-1, 1) * 0.5)
168
+ ai_predict = golden_label
169
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
170
  num2 += 1
171
  else:
172
  if abs(human_predict - golden_label) < abs(ai_predict - golden_label):
173
+ if abs(human_predict - golden_label) < 2:
174
  golden_label = int((golden_label + human_predict) / 2)
175
+ ai_predict += int(random.randint(-1, 1) * 0.5)
176
  chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are closer to the answer and better than AI!", user_select))
177
  num1 += 1
178
  else:
179
+ gold_label = int(gold_label)
180
+ ai_predict = int(ai_predict)
181
  chatbot.append(("The correct answer is " + str(golden_label) + ". Both wrong... Maybe next time you'll win!", user_select))
182
  else:
183
+ gold_label = int(gold_label)
184
+ ai_predict = int(ai_predict)
185
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! πŸ˜‰", user_select))
186
  else:
187
+ if golden_label == 10:
188
+ if ai_predict > 5 and human_predict > 5:
189
+ golden_label = int((human_predict + ai_predict)/2) + random.randint(-1, 1)
190
+ while golden_label > 10:
191
+ golden_label = int((human_predict + ai_predict)/2) + random.randint(-1, 1)
192
  ai_predict = int((golden_label + ai_predict) / 2)
193
  chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
194
  num1 += 1
195
  num2 += 1
196
+ elif ai_predict > 5 and human_predict <= 5:
197
+ golden_label -= random.randint(0, 3)
198
+ ai_predict = 7 + random.randint(-1, 2)
199
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
200
  num2 += 1
201
+ elif ai_predict <= 5 and human_predict > 5:
202
+ golden_label = human_predict + random.randint(-1, 1)
203
+ while golden_label > 10:
204
+ golden_label = human_predict + random.randint(-1, 1)
205
+ ai_predict = int(ai_predict)
206
  chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are close to the answer and better than AI!", user_select))
207
  num1 += 1
208
  else:
209
+ gold_label = int(gold_label)
210
+ ai_predict = int(ai_predict)
211
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry... No one gets the correct answer. But nice try! πŸ˜‰", user_select))
212
  else:
213
+ if ai_predict < 5 and human_predict < 5:
214
+ golden_label = int((human_predict + ai_predict)/2) + random.randint(-1, 1)
215
  while golden_label < 0:
216
+ golden_label = int((human_predict + ai_predict)/2) + random.randint(-1, 1)
217
  ai_predict = int((golden_label + ai_predict) / 2)
218
  chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! πŸŽ‰ Both of you get the correct answer!", user_select))
219
  num1 += 1
220
  num2 += 1
221
+ elif ai_predict < 5 and human_predict >= 5:
222
+ golden_label += random.randint(0, 3)
223
+ ai_predict = 3 + random.randint(-2, 1)
224
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
225
  num2 += 1
226
+ elif ai_predict >= 5 and human_predict < 5:
227
+ golden_label = human_predict + random.randint(-1, 1)
228
  while golden_label < 0:
229
+ golden_label = human_predict + random.randint(-1, 1)
230
+ ai_predict = int(ai_predict)
231
  chatbot.append(("The correct answer is " + str(golden_label) + ". Great! πŸŽ‰ You are close to the answer and better than AI!", user_select))
232
  num1 += 1
233
  else:
234
+ gold_label = int(gold_label)
235
+ ai_predict = int(ai_predict)
236
  chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry... No one gets the correct answer. But nice try! πŸ˜‰", user_select))
237
 
238
  # data = pd.DataFrame(
 
246
  tot_scores = ''' ### <p style="text-align: center;"> πŸ€– Machine &ensp; ''' + str(int(num2)) + ''' &ensp; VS &ensp; ''' + str(int(num1)) + ''' &ensp; Human πŸ‘¨πŸ‘© </p>'''
247
 
248
 
249
+ # num_tmp = max(num1, num2)
250
+ # y_lim_upper = (int((num_tmp + 3)/10)+1) * 10
251
  # figure = gr.BarPlot.update(
252
  # data,
253
  # x="Role",
 
345
  output = classifier([text_written])
346
 
347
  star2num = {
348
+ "5 stars": 10,
349
+ "4 stars": 7.5,
350
+ "3 stars": 5,
351
+ "2 stars": 2.5,
352
  "1 star": 0,
353
  }
354
  print(output)
 
359
  ai_predict = star2num[out['label']]
360
  # result[label] = out['score']
361
 
362
+ if abs(ai_predict - human_predict) <= 2:
363
+ ai_predict = int(ai_predict)
364
  chatbot.append(("AI gives it a close score! πŸŽ‰", "⬅️ Feel free to try another one! ⬅️"))
365
  else:
366
+ ai_predict += int(random.randint(-1, 1))
367
+ while ai_predict > 10 or ai_predict < 0:
368
+ ai_predict += int(random.randint(-1, 1))
369
  chatbot.append(("AI thinks in a different way from human. πŸ˜‰", "⬅️ Feel free to try another one! ⬅️"))
370
 
371