Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ if 'index' not in st.session_state:
|
|
13 |
if 'game_over' not in st.session_state:
|
14 |
st.session_state.game_over = False
|
15 |
|
16 |
-
# Function to get
|
17 |
def get_next_text():
|
18 |
# If game is over, return None to stop
|
19 |
if st.session_state.game_over:
|
@@ -27,10 +27,10 @@ def get_next_text():
|
|
27 |
|
28 |
# Combine the text and make sure it doesn't exceed 10 sentences
|
29 |
full_text = prompt_text + " _SEP_ " + gen_text
|
30 |
-
return
|
31 |
|
32 |
# Function to update the game state
|
33 |
-
def update_game_state(user_answer, correct_answer):
|
34 |
# Check if answer is correct
|
35 |
if user_answer == correct_answer:
|
36 |
st.session_state.score += 5
|
@@ -41,26 +41,44 @@ def update_game_state(user_answer, correct_answer):
|
|
41 |
else:
|
42 |
st.session_state.game_over = True
|
43 |
st.error("Game Over! Incorrect Answer.")
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Display the score
|
46 |
st.sidebar.text(f"Score: {st.session_state.score}")
|
47 |
|
48 |
# Show the current text to classify
|
49 |
-
|
50 |
|
51 |
-
if
|
52 |
-
# Display the text
|
|
|
53 |
st.write(f"Model used: {model_used}")
|
54 |
-
st.write(f"Text: {
|
55 |
|
|
|
|
|
|
|
|
|
56 |
# User input (radio buttons for classification)
|
57 |
-
user_answer = st.radio("Classify the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# When user submits answer
|
60 |
if st.button("Submit"):
|
61 |
# Correct answer is determined based on boundary index
|
62 |
correct_answer = "human" if true_boundary_index == 0 else "machine"
|
63 |
-
update_game_state(user_answer, correct_answer)
|
64 |
else:
|
65 |
# Game over message
|
66 |
st.write("Game Over!")
|
|
|
13 |
if 'game_over' not in st.session_state:
|
14 |
st.session_state.game_over = False
|
15 |
|
16 |
+
# Function to get the current text pair from the dataset
|
17 |
def get_next_text():
|
18 |
# If game is over, return None to stop
|
19 |
if st.session_state.game_over:
|
|
|
27 |
|
28 |
# Combine the text and make sure it doesn't exceed 10 sentences
|
29 |
full_text = prompt_text + " _SEP_ " + gen_text
|
30 |
+
return prompt_text, gen_text, text_data['model'], text_data['true_boundary_index']
|
31 |
|
32 |
# Function to update the game state
|
33 |
+
def update_game_state(user_answer, correct_answer, user_reason=None):
|
34 |
# Check if answer is correct
|
35 |
if user_answer == correct_answer:
|
36 |
st.session_state.score += 5
|
|
|
41 |
else:
|
42 |
st.session_state.game_over = True
|
43 |
st.error("Game Over! Incorrect Answer.")
|
44 |
+
|
45 |
+
# If user chose machine, display their reason
|
46 |
+
if user_answer == 'machine' and user_reason:
|
47 |
+
st.write(f"Reason selected: {user_reason}")
|
48 |
|
49 |
# Display the score
|
50 |
st.sidebar.text(f"Score: {st.session_state.score}")
|
51 |
|
52 |
# Show the current text to classify
|
53 |
+
prompt_text, gen_text, model_used, true_boundary_index = get_next_text()
|
54 |
|
55 |
+
if prompt_text:
|
56 |
+
# Display the human-generated text
|
57 |
+
st.header("Human-Generated Text")
|
58 |
st.write(f"Model used: {model_used}")
|
59 |
+
st.write(f"Text: {prompt_text}")
|
60 |
|
61 |
+
# Display the continuation text
|
62 |
+
st.header("Continuation Text")
|
63 |
+
st.write(f"{gen_text}")
|
64 |
+
|
65 |
# User input (radio buttons for classification)
|
66 |
+
user_answer = st.radio("Classify the continuation as:", ["human", "machine"])
|
67 |
+
|
68 |
+
# If user selects 'machine', ask for reasoning
|
69 |
+
if user_answer == 'machine':
|
70 |
+
user_reason = st.selectbox("Why do you think it's machine-generated?", [
|
71 |
+
"grammar", "repetition", "irrelevant", "contradicts_sentence", "contradicts_knowledge",
|
72 |
+
"common_sense", "coreference", "generic", "other"
|
73 |
+
])
|
74 |
+
else:
|
75 |
+
user_reason = None
|
76 |
|
77 |
# When user submits answer
|
78 |
if st.button("Submit"):
|
79 |
# Correct answer is determined based on boundary index
|
80 |
correct_answer = "human" if true_boundary_index == 0 else "machine"
|
81 |
+
update_game_state(user_answer, correct_answer, user_reason)
|
82 |
else:
|
83 |
# Game over message
|
84 |
st.write("Game Over!")
|