sepp81 commited on
Commit
7f14c2d
·
verified ·
1 Parent(s): 349ad50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -43
app.py CHANGED
@@ -2,8 +2,8 @@ import streamlit as st
2
  import pandas as pd
3
  import random
4
 
5
- # Load the dataset (replace with your actual dataset path)
6
- df = pd.read_csv('roft.csv') # Ensure your dataset path is correct
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
- # Combine the prompt body and generation body to form the text to classify
25
  prompt_text = text_data['prompt_body']
26
  gen_text = text_data['gen_body']
 
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
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
- 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!")
85
- st.write(f"Your final score is: {st.session_state.score}")
 
 
86
 
87
- # Option to restart the game
88
- if st.session_state.game_over:
89
- if st.button("Restart Game"):
90
- st.session_state.score = 0
91
- st.session_state.index = 0
92
- st.session_state.game_over = False
93
- st.experimental_rerun()
 
 
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}")