Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,8 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import random
|
4 |
|
5 |
-
# Load the dataset (
|
6 |
-
df = pd.read_csv('roft.csv') #
|
7 |
|
8 |
# Initialize session state variables
|
9 |
if 'score' not in st.session_state:
|
@@ -21,17 +21,22 @@ def get_next_text():
|
|
21 |
# Fetch the next text in sequence
|
22 |
text_data = df.iloc[st.session_state.index]
|
23 |
|
24 |
-
#
|
25 |
prompt_text = text_data['prompt_body']
|
26 |
gen_text = text_data['gen_body']
|
|
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
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
|
37 |
st.session_state.index += 1
|
@@ -50,44 +55,40 @@ def update_game_state(user_answer, correct_answer, user_reason=None):
|
|
50 |
st.sidebar.text(f"Score: {st.session_state.score}")
|
51 |
|
52 |
# Show the current text to classify
|
53 |
-
|
|
|
54 |
|
55 |
-
if prompt_text:
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# Display the continuation text
|
62 |
-
st.header("Continuation Text")
|
63 |
-
st.write(f"{gen_text}")
|
64 |
|
65 |
-
|
66 |
-
|
|
|
67 |
|
68 |
-
|
69 |
-
|
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 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
|
87 |
-
#
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
2 |
import pandas as pd
|
3 |
import random
|
4 |
|
5 |
+
# Load the dataset (ensure the file path is correct)
|
6 |
+
df = pd.read_csv('roft.csv') # Replace with the actual dataset path
|
7 |
|
8 |
# Initialize session state variables
|
9 |
if 'score' not in st.session_state:
|
|
|
21 |
# Fetch the next text in sequence
|
22 |
text_data = df.iloc[st.session_state.index]
|
23 |
|
24 |
+
# Extract prompt and generation text
|
25 |
prompt_text = text_data['prompt_body']
|
26 |
gen_text = text_data['gen_body']
|
27 |
+
model_used = text_data['model']
|
28 |
|
29 |
+
# Get the continuation text (sentence before "_SEP_")
|
30 |
+
continuation_text = gen_text.split("_SEP_")[0].strip()
|
31 |
+
|
32 |
+
# Get the true boundary index (where human text ends and machine text begins)
|
33 |
+
true_boundary_index = text_data['true_boundary_index']
|
34 |
+
|
35 |
+
return prompt_text, continuation_text, gen_text, model_used, true_boundary_index
|
36 |
|
37 |
# Function to update the game state
|
38 |
def update_game_state(user_answer, correct_answer, user_reason=None):
|
39 |
+
# Check if the answer is correct
|
40 |
if user_answer == correct_answer:
|
41 |
st.session_state.score += 5
|
42 |
st.session_state.index += 1
|
|
|
55 |
st.sidebar.text(f"Score: {st.session_state.score}")
|
56 |
|
57 |
# Show the current text to classify
|
58 |
+
if not st.session_state.game_over:
|
59 |
+
prompt_text, continuation_text, gen_text, model_used, true_boundary_index = get_next_text()
|
60 |
|
61 |
+
if prompt_text:
|
62 |
+
# Display the human-generated text (more readable format)
|
63 |
+
st.header("Human-Generated Text")
|
64 |
+
st.write(f"Model used: {model_used}")
|
65 |
+
st.write("Text: ")
|
66 |
+
st.markdown(f"**{prompt_text}**")
|
|
|
|
|
|
|
67 |
|
68 |
+
# Display the continuation text (sentence before _SEP_)
|
69 |
+
st.header("Continuation Text")
|
70 |
+
st.write(f"{continuation_text}")
|
71 |
|
72 |
+
# User input (radio buttons for classification)
|
73 |
+
user_answer = st.radio("Classify the continuation as:", ["human", "machine"])
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
# If user selects 'machine', ask for reasoning
|
76 |
+
if user_answer == 'machine':
|
77 |
+
user_reason = st.selectbox("Why do you think it's machine-generated?", [
|
78 |
+
"grammar", "repetition", "irrelevant", "contradicts_sentence", "contradicts_knowledge",
|
79 |
+
"common_sense", "coreference", "generic"
|
80 |
+
])
|
81 |
+
|
82 |
+
# Button to submit answer
|
83 |
+
if st.button('Submit'):
|
84 |
+
correct_answer = 'machine' if true_boundary_index != 0 else 'human'
|
85 |
+
update_game_state(user_answer, correct_answer, user_reason)
|
86 |
|
87 |
+
# Button to submit answer if 'human' is selected
|
88 |
+
elif st.button('Submit'):
|
89 |
+
correct_answer = 'human' if true_boundary_index == 0 else 'machine'
|
90 |
+
update_game_state(user_answer, correct_answer)
|
91 |
+
|
92 |
+
else:
|
93 |
+
# If the game is over, display the final score
|
94 |
+
st.write(f"Final Score: {st.session_state.score}")
|