Yara Kyrychenko
commited on
Commit
Β·
fee93ee
1
Parent(s):
24eeeaa
refuse greetings
Browse files
app.py
CHANGED
|
@@ -69,15 +69,16 @@ if 'inserted' not in st.session_state:
|
|
| 69 |
st.session_state.convo_start_time = ''
|
| 70 |
|
| 71 |
if 'p' not in st.query_params or st.query_params['p'] == '':
|
| 72 |
-
st.query_params['p'] =
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
if 'id' not in st.query_params:
|
| 77 |
st.query_params['id'] = st.session_state.random_pid
|
| 78 |
if 'party' not in st.query_params or st.query_params['party'] == '':
|
| 79 |
-
st.session_state.party = st.radio("Generally speaking, do you usually think of yourself as a Republican
|
| 80 |
-
['','Republican', 'Democrat'
|
| 81 |
st.query_params['party'] = st.session_state.party
|
| 82 |
|
| 83 |
def setup_messages():
|
|
@@ -115,11 +116,13 @@ with st.sidebar:
|
|
| 115 |
|
| 116 |
st.markdown("π Some example topics include gun laws, abortion, and immigration.")
|
| 117 |
|
|
|
|
|
|
|
| 118 |
st.markdown(f"""
|
| 119 |
β οΈ You must respond **at least 5 times** before you will see a *Submit Interaction* button. You can continue before submitting, but **you must Submit Interaction and enter your chatbot word to proceed with the survey**.
|
| 120 |
|
| 121 |
-
β Do not share any personal information (e.g., name or address). Do not use AI tools to generate your responses; write them yourself.
|
| 122 |
-
|
| 123 |
β If you encounter any technical issues, please let us know. It might sometimes take 30 seconds or more to generate a response, so please be patient.
|
| 124 |
|
| 125 |
{"β" if st.session_state.inserted > 1 else "β"} **Step 3. Use the *Submit Interaction* button to get your chatbot word**
|
|
@@ -200,7 +203,22 @@ elif st.session_state.inserted > 1:
|
|
| 200 |
st.markdown('**Please copy the WORD and enter it into the survey field below.**')
|
| 201 |
|
| 202 |
elif prompt := st.chat_input("Type to ask a question or respond..."):
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 205 |
with st.chat_message("user"):
|
| 206 |
st.markdown(prompt)
|
|
|
|
| 69 |
st.session_state.convo_start_time = ''
|
| 70 |
|
| 71 |
if 'p' not in st.query_params or st.query_params['p'] == '':
|
| 72 |
+
st.query_params['p'] = '1'
|
| 73 |
+
#st.query_params['p'] = st.radio("Select a condition for the conversation",
|
| 74 |
+
# ['', '1', '2', '3', '4'],
|
| 75 |
+
# help="1 = base, 2 = bridging, 3 = personalization, 4 = bridging + personalization")
|
| 76 |
|
| 77 |
if 'id' not in st.query_params:
|
| 78 |
st.query_params['id'] = st.session_state.random_pid
|
| 79 |
if 'party' not in st.query_params or st.query_params['party'] == '':
|
| 80 |
+
st.session_state.party = st.radio("Generally speaking, do you usually think of yourself as a Republican or a Democrat?",
|
| 81 |
+
['','Republican', 'Democrat'])
|
| 82 |
st.query_params['party'] = st.session_state.party
|
| 83 |
|
| 84 |
def setup_messages():
|
|
|
|
| 116 |
|
| 117 |
st.markdown("π Some example topics include gun laws, abortion, and immigration.")
|
| 118 |
|
| 119 |
+
st.markdown("β Please avoid greetings and start the conversation with a question or a statement about a politically polarizing topic.")
|
| 120 |
+
|
| 121 |
st.markdown(f"""
|
| 122 |
β οΈ You must respond **at least 5 times** before you will see a *Submit Interaction* button. You can continue before submitting, but **you must Submit Interaction and enter your chatbot word to proceed with the survey**.
|
| 123 |
|
| 124 |
+
β Do not share any personal information (e.g., name or address). Do not use AI tools to generate your responses; write them yourself.
|
| 125 |
+
|
| 126 |
β If you encounter any technical issues, please let us know. It might sometimes take 30 seconds or more to generate a response, so please be patient.
|
| 127 |
|
| 128 |
{"β" if st.session_state.inserted > 1 else "β"} **Step 3. Use the *Submit Interaction* button to get your chatbot word**
|
|
|
|
| 203 |
st.markdown('**Please copy the WORD and enter it into the survey field below.**')
|
| 204 |
|
| 205 |
elif prompt := st.chat_input("Type to ask a question or respond..."):
|
| 206 |
+
if len(st.session_state.messages) == 1:
|
| 207 |
+
clean_prompt = prompt.strip().lower()
|
| 208 |
+
clean_prompt = clean_prompt.strip("!,.?")
|
| 209 |
+
greetings = {
|
| 210 |
+
"hi", "hello", "hey", "heya", "hiya", "yo", "howdy", "sup",
|
| 211 |
+
"good morning", "good afternoon", "good evening", "good day",
|
| 212 |
+
"what's up", "whats up"
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
if clean_prompt in greetings:
|
| 216 |
+
st.error(
|
| 217 |
+
"Please avoid greetings and start the conversation with a question or a statement about a politically polarizing topic.",
|
| 218 |
+
icon="π«"
|
| 219 |
+
)
|
| 220 |
+
st.stop()
|
| 221 |
+
|
| 222 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 223 |
with st.chat_message("user"):
|
| 224 |
st.markdown(prompt)
|