Spaces:
Sleeping
Sleeping
Update game3.py
Browse files
game3.py
CHANGED
|
@@ -40,9 +40,9 @@ def func3(num_selected, human_predict, num1, num2, user_important):
|
|
| 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
|
|
@@ -55,8 +55,10 @@ def func3(num_selected, human_predict, num1, num2, user_important):
|
|
| 55 |
|
| 56 |
# (END) off-the-shelf version
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
user_select = "You focused on "
|
| 62 |
flag_select = False
|
|
@@ -76,28 +78,20 @@ def func3(num_selected, human_predict, num1, num2, user_important):
|
|
| 76 |
# if not flag_select:
|
| 77 |
# user_select += "nothing. Interesting! "
|
| 78 |
user_select += "Wanna see how the AI made the guess? Click here. β¬
οΈ"
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
num2 += 1
|
| 91 |
else:
|
| 92 |
-
|
| 93 |
-
|
| 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   ''' + str(int(num2)) + '''   VS   ''' + str(int(num1)) + '''   Human </p>'''
|
| 103 |
|
|
@@ -169,19 +163,16 @@ def func3_written(text_written, human_predict, lang_written):
|
|
| 169 |
out = output[0]
|
| 170 |
# (END) off-the-shelf version
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
-
ai_predict = out['score']
|
| 175 |
-
|
| 176 |
-
if abs(ai_predict - human_predict) <= 12.5:
|
| 177 |
chatbot.append(("AI gives it a close score! π", "β¬
οΈ Feel free to try another one! β¬
οΈ"))
|
| 178 |
else:
|
| 179 |
-
ai_predict += random.randint(-2, 2)
|
| 180 |
-
while ai_predict > 100 or ai_predict < 0 or ai_predict % 25 == 0:
|
| 181 |
-
ai_predict += random.randint(-2, 2)
|
| 182 |
chatbot.append(("AI thinks in a different way from human. π", "β¬
οΈ Feel free to try another one! β¬
οΈ"))
|
| 183 |
|
| 184 |
-
|
| 185 |
import shap
|
| 186 |
|
| 187 |
gender_classifier = pipeline("text-classification", model="padmajabfrl/Gender-Classification", return_all_scores=True)
|
|
|
|
| 40 |
|
| 41 |
golden_label = (text['binary_label']^1) * 100
|
| 42 |
if golden_label == 0:
|
| 43 |
+
golden_label = int(50 * (1 - text['binary_score']))
|
| 44 |
else:
|
| 45 |
+
golden_label = int(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
|
|
|
|
| 55 |
|
| 56 |
# (END) off-the-shelf version
|
| 57 |
|
| 58 |
+
if out['label'] == 'Female':
|
| 59 |
+
ai_predict = int(out['score'])
|
| 60 |
+
else:
|
| 61 |
+
ai_predict = 1 - int(out['score'])
|
| 62 |
|
| 63 |
user_select = "You focused on "
|
| 64 |
flag_select = False
|
|
|
|
| 78 |
# if not flag_select:
|
| 79 |
# user_select += "nothing. Interesting! "
|
| 80 |
user_select += "Wanna see how the AI made the guess? Click here. β¬
οΈ"
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if abs(golden_label - human_predict) <= 20 and abs(golden_label - ai_predict) <= 20:
|
| 84 |
+
chatbot.append(("The correct answer is " + str(golden_label) + ". Congratulations! π Both of you get the correct answer!", user_select))
|
| 85 |
+
num1 += 1
|
| 86 |
+
num2 += 1
|
| 87 |
+
elif abs(golden_label - human_predict) > 20 and abs(golden_label - ai_predict) > 20:
|
| 88 |
+
chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. No one gets the correct answer. But nice try! π", user_select))
|
| 89 |
+
elif abs(golden_label - human_predict) <= 20 and abs(golden_label - ai_predict) > 20:
|
| 90 |
+
chatbot.append(("The correct answer is " + str(golden_label) + ". Great! π You are closer to the answer and better than AI!", user_select))
|
| 91 |
+
num1 += 1
|
|
|
|
| 92 |
else:
|
| 93 |
+
chatbot.append(("The correct answer is " + str(golden_label) + ". Sorry.. AI wins in this round.", user_select))
|
| 94 |
+
num2 += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
tot_scores = ''' ### <p style="text-align: center;"> Machine   ''' + str(int(num2)) + '''   VS   ''' + str(int(num1)) + '''   Human </p>'''
|
| 97 |
|
|
|
|
| 163 |
out = output[0]
|
| 164 |
# (END) off-the-shelf version
|
| 165 |
|
| 166 |
+
if out['label'] == 'Female':
|
| 167 |
+
ai_predict = int(out['score'])
|
| 168 |
+
else:
|
| 169 |
+
ai_predict = 1 - int(out['score'])
|
| 170 |
|
| 171 |
+
if abs(ai_predict - human_predict) <= 20:
|
|
|
|
|
|
|
|
|
|
| 172 |
chatbot.append(("AI gives it a close score! π", "β¬
οΈ Feel free to try another one! β¬
οΈ"))
|
| 173 |
else:
|
|
|
|
|
|
|
|
|
|
| 174 |
chatbot.append(("AI thinks in a different way from human. π", "β¬
οΈ Feel free to try another one! β¬
οΈ"))
|
| 175 |
|
|
|
|
| 176 |
import shap
|
| 177 |
|
| 178 |
gender_classifier = pipeline("text-classification", model="padmajabfrl/Gender-Classification", return_all_scores=True)
|