Spaces:
Runtime error
Runtime error
Update game1.py
Browse files
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'] *
|
81 |
else:
|
82 |
-
golden_label = text['label'] *
|
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":
|
125 |
-
"4 stars":
|
126 |
-
"3 stars":
|
127 |
-
"2 stars":
|
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) <
|
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(-
|
164 |
-
while golden_label >
|
165 |
-
golden_label += random.randint(-
|
|
|
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) <
|
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 ==
|
180 |
-
if ai_predict >
|
181 |
-
golden_label = int((human_predict + ai_predict)/2) + random.randint(-
|
182 |
-
while golden_label >
|
183 |
-
golden_label = int((human_predict + ai_predict)/2) + random.randint(-
|
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 >
|
189 |
-
golden_label -= random.randint(0,
|
190 |
-
ai_predict =
|
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 <=
|
194 |
-
golden_label = human_predict + random.randint(-
|
195 |
-
while golden_label >
|
196 |
-
golden_label = human_predict + random.randint(-
|
|
|
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 <
|
203 |
-
golden_label = int((human_predict + ai_predict)/2) + random.randint(-
|
204 |
while golden_label < 0:
|
205 |
-
golden_label = int((human_predict + ai_predict)/2) + random.randint(-
|
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 <
|
211 |
-
golden_label += random.randint(0,
|
212 |
-
ai_predict =
|
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 >=
|
216 |
-
golden_label = human_predict + random.randint(-
|
217 |
while golden_label < 0:
|
218 |
-
golden_label = human_predict + random.randint(-
|
|
|
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   ''' + str(int(num2)) + '''   VS   ''' + str(int(num1)) + '''   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":
|
335 |
-
"4 stars":
|
336 |
-
"3 stars":
|
337 |
-
"2 stars":
|
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) <=
|
|
|
349 |
chatbot.append(("AI gives it a close score! π", "β¬
οΈ Feel free to try another one! β¬
οΈ"))
|
350 |
else:
|
351 |
-
ai_predict += random.randint(-
|
352 |
-
while ai_predict >
|
353 |
-
ai_predict += random.randint(-
|
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   ''' + str(int(num2)) + '''   VS   ''' + str(int(num1)) + '''   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 |
|