Ashmi Banerjee commited on
Commit
e3f0784
·
1 Parent(s): 897c1d2

added code validation

Browse files
Files changed (2) hide show
  1. README.md +7 -1
  2. app.py +25 -12
README.md CHANGED
@@ -18,4 +18,10 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
18
  [ ] Consent form
19
  [ ] Instructions
20
  [ ] Add proceed button after prolific id
21
- [ ] Make sure each question has at least 10 responses
 
 
 
 
 
 
 
18
  [ ] Consent form
19
  [ ] Instructions
20
  [ ] Add proceed button after prolific id
21
+ [ ] Make sure each question has at least 10 responses
22
+
23
+ ### TODO List (Human Eval)
24
+ [ ] Check if user_id in database, then resume where they left off
25
+ [ ] Implement save and continue later button
26
+ [ ] Implement questions
27
+ [ ] Back button
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  from db.schema import Feedback, Response
2
  from db.crud import ingest
3
  import pandas as pd
@@ -5,10 +8,9 @@ import streamlit as st
5
  from datetime import datetime
6
  import os
7
  from dotenv import load_dotenv
8
- import json
9
- from typing import Dict, List
10
 
11
  load_dotenv()
 
12
 
13
 
14
  class SurveyState:
@@ -46,10 +48,6 @@ class SurveyState:
46
  return {}
47
 
48
 
49
- def validate_prolific_id(prolific_id: str) -> bool:
50
- return bool(prolific_id.strip())
51
-
52
-
53
  def initialization():
54
  """Initialize session state variables."""
55
  if "current_index" not in st.session_state:
@@ -64,13 +62,25 @@ def initialization():
64
  st.session_state.survey_state = SurveyState()
65
 
66
 
 
 
 
 
 
 
 
 
 
67
  def prolific_id_screen():
68
  """Display the Prolific ID entry screen."""
69
  st.title("Welcome to the Feedback Survey")
 
70
  prolific_id_input = st.text_input("Enter your Prolific ID and press ENTER:")
 
71
 
72
- if prolific_id_input:
73
- if validate_prolific_id(prolific_id_input):
 
74
  st.session_state.prolific_id = prolific_id_input
75
 
76
  # Load previous state if exists
@@ -80,10 +90,13 @@ def prolific_id_screen():
80
  st.session_state.responses = saved_state.get('responses', [])
81
  st.success("Previous progress loaded! Continuing from where you left off.")
82
  else:
83
- st.success("Prolific ID recorded! Starting new survey.")
84
  st.rerun()
85
  else:
86
- st.warning("Invalid Prolific ID. Please check and try again.")
 
 
 
87
 
88
 
89
  def questions_screen(data):
@@ -120,7 +133,7 @@ def questions_screen(data):
120
  rating_p0 = st.radio("Rate this config:", options, key=f"rating_p0_{current_index}")
121
 
122
  st.write(f"**Query_p1:** {config['query_p1']}")
123
- rating_p1 = st.radio("Rate this config:", options, key=f"rating_p1_{current_index}")
124
 
125
  comment = st.text_area("Comments (Optional):")
126
  response = Response(config_id=config["config_id"],
@@ -147,7 +160,7 @@ def navigation_buttons(data, rating_v, rating_p0, rating_p1):
147
 
148
  with col2: # Next button
149
  if st.button("Next"):
150
- if rating_v == 0 or rating_p0 == 0 or rating_p1 ==0:
151
  st.warning("Please provide a rating before proceeding.")
152
  else:
153
  if current_index < len(data) - 1:
 
1
+ import json
2
+ from typing import Dict
3
+
4
  from db.schema import Feedback, Response
5
  from db.crud import ingest
6
  import pandas as pd
 
8
  from datetime import datetime
9
  import os
10
  from dotenv import load_dotenv
 
 
11
 
12
  load_dotenv()
13
+ VALIDATION_CODE = os.getenv("VALIDATION_CODE")
14
 
15
 
16
  class SurveyState:
 
48
  return {}
49
 
50
 
 
 
 
 
51
  def initialization():
52
  """Initialize session state variables."""
53
  if "current_index" not in st.session_state:
 
62
  st.session_state.survey_state = SurveyState()
63
 
64
 
65
+ def validate_prolific_id(prolific_id: str) -> bool:
66
+ return bool(prolific_id.strip())
67
+
68
+
69
+ def validate_code(input_code: str) -> bool:
70
+ """Validate the entered code against the hardcoded validation code"""
71
+ return input_code.strip() == VALIDATION_CODE
72
+
73
+
74
  def prolific_id_screen():
75
  """Display the Prolific ID entry screen."""
76
  st.title("Welcome to the Feedback Survey")
77
+
78
  prolific_id_input = st.text_input("Enter your Prolific ID and press ENTER:")
79
+ validation_code_input = st.text_input("Enter the validation code to proceed:")
80
 
81
+ if prolific_id_input and validation_code_input:
82
+ # Validate Prolific ID and code
83
+ if validate_prolific_id(prolific_id_input) and validate_code(validation_code_input):
84
  st.session_state.prolific_id = prolific_id_input
85
 
86
  # Load previous state if exists
 
90
  st.session_state.responses = saved_state.get('responses', [])
91
  st.success("Previous progress loaded! Continuing from where you left off.")
92
  else:
93
+ st.success("Prolific ID and code validated! Starting new survey.")
94
  st.rerun()
95
  else:
96
+ if not validate_prolific_id(prolific_id_input):
97
+ st.warning("Invalid Prolific ID. Please check and try again.")
98
+ if not validate_code(validation_code_input):
99
+ st.warning("Invalid validation code. Please check and try again.")
100
 
101
 
102
  def questions_screen(data):
 
133
  rating_p0 = st.radio("Rate this config:", options, key=f"rating_p0_{current_index}")
134
 
135
  st.write(f"**Query_p1:** {config['query_p1']}")
136
+ rating_p1 = st.radio("Rate this config:", options, key=f"rating_p1_{current_index}")
137
 
138
  comment = st.text_area("Comments (Optional):")
139
  response = Response(config_id=config["config_id"],
 
160
 
161
  with col2: # Next button
162
  if st.button("Next"):
163
+ if rating_v == 0 or rating_p0 == 0 or rating_p1 == 0:
164
  st.warning("Please provide a rating before proceeding.")
165
  else:
166
  if current_index < len(data) - 1: