Spaces:
Running
Running
Yara Kyrychenko
commited on
Commit
·
9fd35e2
1
Parent(s):
e1e090f
upd t and m
Browse files- app.py +45 -40
- knowledge.txt +1 -1
- personalization.txt +5 -5
app.py
CHANGED
|
@@ -57,20 +57,17 @@ if 'inserted' not in st.session_state:
|
|
| 57 |
|
| 58 |
# user info state
|
| 59 |
st.session_state.fields = [
|
| 60 |
-
'climate_actions', 'age', 'gender', 'education', 'residence',
|
| 61 |
-
'property', #'income', 'zipcode',
|
| 62 |
'politics', 'impact_open', 'ev',
|
| 63 |
-
'fossil', 'aerosol', 'diet', 'recycling'
|
|
|
|
| 64 |
]
|
| 65 |
|
| 66 |
for field in st.session_state.fields:
|
| 67 |
st.session_state[field] = ''
|
| 68 |
|
| 69 |
-
st.session_state.user_id = ''
|
| 70 |
-
|
| 71 |
st.session_state.recycling = 0
|
| 72 |
|
| 73 |
-
|
| 74 |
# timers
|
| 75 |
st.session_state.start_time = datetime.now()
|
| 76 |
st.session_state.convo_start_time = ''
|
|
@@ -79,7 +76,10 @@ if 'p' not in st.query_params:
|
|
| 79 |
st.query_params['p'] = 't'
|
| 80 |
|
| 81 |
def setup_messages():
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
if st.query_params["p"] == "f" or st.query_params["p"] == "n":
|
| 85 |
st.session_state.system_message = st.session_state.base_text
|
|
@@ -88,7 +88,6 @@ def setup_messages():
|
|
| 88 |
elif st.query_params["p"] == "t":
|
| 89 |
st.session_state.system_message = format_personalization(st.session_state.personalization_text)
|
| 90 |
|
| 91 |
-
print(st.session_state.system_message)
|
| 92 |
st.session_state.messages = [{ "role": "system", "content": st.session_state.system_message}]
|
| 93 |
st.session_state.convo_start_time = datetime.now()
|
| 94 |
|
|
@@ -118,12 +117,14 @@ with st.sidebar:
|
|
| 118 |
{"🎉 **All done! Please press *Next* in the survey.**" if st.session_state.inserted > 0 else ""}
|
| 119 |
""")
|
| 120 |
if st.session_state.gotit == False:
|
|
|
|
| 121 |
st.session_state.gotit = st.button("Let's start!", key=None, help=None, use_container_width=True)
|
| 122 |
|
| 123 |
|
| 124 |
@st.dialog('Form')
|
| 125 |
def form():
|
| 126 |
-
st.markdown("
|
|
|
|
| 127 |
st.session_state.age = st.text_input("How old are you in years?")
|
| 128 |
st.session_state.gender = st.radio("Do you describe yourself as a man, a woman, or in some other way?",
|
| 129 |
['','Man', 'Woman', 'Other'])
|
|
@@ -137,12 +138,9 @@ def form():
|
|
| 137 |
'Doctorate degree (e.g., PhD, MD)'])
|
| 138 |
st.session_state.residence = st.radio("What type of a community do you live in?",
|
| 139 |
['', 'Urban','Suburban','Rural','Other'])
|
| 140 |
-
#st.session_state.zipcode = st.text_input("What is your US Zip Code?")
|
| 141 |
st.session_state.property = st.radio("Do you own or rent the home in which you live?",
|
| 142 |
['', 'Own','Rent','Neither (I live rent-free)',
|
| 143 |
'Other' ])
|
| 144 |
-
#st.session_state.income = st.radio("What was your total household income before taxes during the past 12 months?",
|
| 145 |
-
# ['','Less than \$25,000','\$25,000 to \$49,999','\$50,000 to \$74,999','\$75,000 to \$99,999','\$100,000 to \$149,999','\$150,000 or more'])
|
| 146 |
st.session_state.politics = st.radio('What is your political orientation?', ['', 'Extremely liberal', 'Liberal', 'Slightly liberal', 'Moderate', 'Slightly conservative', 'Conservative', 'Extremely conservative'])
|
| 147 |
st.session_state.climate_actions = st.text_area('Please describe any actions you are taking to address climate change? Write *None* if you are not taking any.')
|
| 148 |
st.session_state.impact_open = st.text_area('What do you believe is the single most effective action you can take to reduce carbon emissions that contribute to climate change?')
|
|
@@ -156,26 +154,32 @@ def form():
|
|
| 156 |
st.session_state.diet = st.radio('Lab-grown meat produces up to 25 times more CO2 than real meat.', ["", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"])
|
| 157 |
|
| 158 |
|
| 159 |
-
#st.session_state.user_info = st.text_area(
|
| 160 |
-
#"Write at least two sentences about yourself. You can write about your job, hobbies, living arrangements or any other information you think might be relevant. **Do not write anything that could identify you, such as your name or address.**",'')
|
| 161 |
-
|
| 162 |
columns_form = st.columns((1,1,1))
|
| 163 |
with columns_form[2]:
|
| 164 |
-
submitted = st.button("Proceed",use_container_width=True
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
|
| 167 |
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
st.session_state.submitted = True
|
| 170 |
setup_messages()
|
| 171 |
st.rerun()
|
| 172 |
|
| 173 |
-
elif submitted and not all_form_completed:
|
| 174 |
-
st.warning('Please answer every question and click *Proceed* again to start a conversation.')
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
#st.write(st.session_state.system_message)
|
| 178 |
-
|
| 179 |
if st.session_state.gotit and st.session_state.submitted == False:
|
| 180 |
form()
|
| 181 |
|
|
@@ -187,31 +191,30 @@ for message in st.session_state.messages:
|
|
| 187 |
@st.dialog('Submit conversation')
|
| 188 |
def submit():
|
| 189 |
st.markdown("You must answer all questions marked with a ❗ to submit.")
|
| 190 |
-
st.session_state.user_id = st.text_input(label="❗ Enter your Prolific ID", value=st.session_state.user_id)
|
| 191 |
if st.query_params["p"] != "n":
|
| 192 |
st.slider('❗ How would you rate the conversation on a scale from *Terrible* to *Perfect*?', 0, 100, format="", key="score", value=50)
|
| 193 |
st.slider('❗ How personalized did the conversation feel, on a scale from *Not at all* to *Extremely personalized*?', 0, 100, format="", key="personalization_score", value=50)
|
| 194 |
st.slider('❗ How knowledgeable do you feel the chatbot was, on a scale from *Not at all* to *Extremely knowledgeable*?', 0, 100, format="", key="knowledge_score", value=50)
|
| 195 |
else:
|
| 196 |
-
st.session_state.score =
|
| 197 |
-
st.session_state.personalization_score =
|
| 198 |
-
st.session_state.knowledge_score =
|
| 199 |
|
| 200 |
st.text_area('Any feedback?',key="feedback")
|
| 201 |
-
if st.button('Submit', key=None, help=None, use_container_width=True, disabled=st.session_state.
|
| 202 |
-
#submission_date = datetime.now() #.strftime("%Y-%m-%d %H:%M:%S")
|
| 203 |
-
|
| 204 |
keys = [
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
| 212 |
|
| 213 |
user_data = {key: st.session_state[key] for key in keys}
|
| 214 |
-
user_data["condition"] =
|
| 215 |
user_data["submission_time"] = datetime.now()
|
| 216 |
|
| 217 |
from pymongo.mongo_client import MongoClient
|
|
@@ -224,7 +227,7 @@ def submit():
|
|
| 224 |
|
| 225 |
st.success('**Your conversation has been submitted! Please proceed with the survey.**', icon="✅")
|
| 226 |
|
| 227 |
-
time.sleep(
|
| 228 |
setup_messages()
|
| 229 |
st.rerun()
|
| 230 |
|
|
@@ -238,6 +241,8 @@ elif st.session_state.submitted == False:
|
|
| 238 |
|
| 239 |
elif st.query_params["p"] == "n":
|
| 240 |
st.markdown("""
|
|
|
|
|
|
|
| 241 |
❗ **Please press *End Conversation* to submit your data and proceed with the survey. You have to submit to receive compensation.**
|
| 242 |
""")
|
| 243 |
columns = st.columns((1,1,1))
|
|
|
|
| 57 |
|
| 58 |
# user info state
|
| 59 |
st.session_state.fields = [
|
| 60 |
+
'climate_actions', 'age', 'gender', 'education', 'residence', 'property',
|
|
|
|
| 61 |
'politics', 'impact_open', 'ev',
|
| 62 |
+
'fossil', 'aerosol', 'diet', 'recycling',
|
| 63 |
+
'user_id'
|
| 64 |
]
|
| 65 |
|
| 66 |
for field in st.session_state.fields:
|
| 67 |
st.session_state[field] = ''
|
| 68 |
|
|
|
|
|
|
|
| 69 |
st.session_state.recycling = 0
|
| 70 |
|
|
|
|
| 71 |
# timers
|
| 72 |
st.session_state.start_time = datetime.now()
|
| 73 |
st.session_state.convo_start_time = ''
|
|
|
|
| 76 |
st.query_params['p'] = 't'
|
| 77 |
|
| 78 |
def setup_messages():
|
| 79 |
+
# t = personalization
|
| 80 |
+
# k = knowledge
|
| 81 |
+
# f = formatting
|
| 82 |
+
# n = no chat
|
| 83 |
|
| 84 |
if st.query_params["p"] == "f" or st.query_params["p"] == "n":
|
| 85 |
st.session_state.system_message = st.session_state.base_text
|
|
|
|
| 88 |
elif st.query_params["p"] == "t":
|
| 89 |
st.session_state.system_message = format_personalization(st.session_state.personalization_text)
|
| 90 |
|
|
|
|
| 91 |
st.session_state.messages = [{ "role": "system", "content": st.session_state.system_message}]
|
| 92 |
st.session_state.convo_start_time = datetime.now()
|
| 93 |
|
|
|
|
| 117 |
{"🎉 **All done! Please press *Next* in the survey.**" if st.session_state.inserted > 0 else ""}
|
| 118 |
""")
|
| 119 |
if st.session_state.gotit == False:
|
| 120 |
+
st.markdown("*You can always return to this panel by clicking the arrow on the top left.*")
|
| 121 |
st.session_state.gotit = st.button("Let's start!", key=None, help=None, use_container_width=True)
|
| 122 |
|
| 123 |
|
| 124 |
@st.dialog('Form')
|
| 125 |
def form():
|
| 126 |
+
st.markdown("**❗ Please answer every question to proceed.**")
|
| 127 |
+
st.session_state.user_id = st.text_input(label="Enter your Prolific ID", value=st.session_state.user_id)
|
| 128 |
st.session_state.age = st.text_input("How old are you in years?")
|
| 129 |
st.session_state.gender = st.radio("Do you describe yourself as a man, a woman, or in some other way?",
|
| 130 |
['','Man', 'Woman', 'Other'])
|
|
|
|
| 138 |
'Doctorate degree (e.g., PhD, MD)'])
|
| 139 |
st.session_state.residence = st.radio("What type of a community do you live in?",
|
| 140 |
['', 'Urban','Suburban','Rural','Other'])
|
|
|
|
| 141 |
st.session_state.property = st.radio("Do you own or rent the home in which you live?",
|
| 142 |
['', 'Own','Rent','Neither (I live rent-free)',
|
| 143 |
'Other' ])
|
|
|
|
|
|
|
| 144 |
st.session_state.politics = st.radio('What is your political orientation?', ['', 'Extremely liberal', 'Liberal', 'Slightly liberal', 'Moderate', 'Slightly conservative', 'Conservative', 'Extremely conservative'])
|
| 145 |
st.session_state.climate_actions = st.text_area('Please describe any actions you are taking to address climate change? Write *None* if you are not taking any.')
|
| 146 |
st.session_state.impact_open = st.text_area('What do you believe is the single most effective action you can take to reduce carbon emissions that contribute to climate change?')
|
|
|
|
| 154 |
st.session_state.diet = st.radio('Lab-grown meat produces up to 25 times more CO2 than real meat.', ["", "Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"])
|
| 155 |
|
| 156 |
|
|
|
|
|
|
|
|
|
|
| 157 |
columns_form = st.columns((1,1,1))
|
| 158 |
with columns_form[2]:
|
| 159 |
+
submitted = st.button("Proceed",use_container_width=True,
|
| 160 |
+
help = 'Please answer every question and click *Proceed* to start a conversation.',
|
| 161 |
+
disabled = not (all(st.session_state[field] != '' for field in st.session_state.fields) and st.session_state.recycling != 0))
|
| 162 |
|
| 163 |
+
if submitted:
|
| 164 |
|
| 165 |
+
user_data = {key: st.session_state[key] for key in st.session_state.fields}
|
| 166 |
+
user_data["model"] = st.session_state["model"]
|
| 167 |
+
user_data["condition"] = st.query_params['p']
|
| 168 |
+
user_data["start_time"] = st.session_state.start_time
|
| 169 |
+
user_data["inserted"] = st.session_state.inserted
|
| 170 |
+
user_data["submission_time"] = datetime.now()
|
| 171 |
+
|
| 172 |
+
from pymongo.mongo_client import MongoClient
|
| 173 |
+
from pymongo.server_api import ServerApi
|
| 174 |
+
with MongoClient(st.secrets["mongo"],server_api=ServerApi('1')) as client:
|
| 175 |
+
db = client.chat
|
| 176 |
+
collection = db.app
|
| 177 |
+
collection.insert_one(user_data)
|
| 178 |
+
st.session_state.inserted += 1
|
| 179 |
st.session_state.submitted = True
|
| 180 |
setup_messages()
|
| 181 |
st.rerun()
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
if st.session_state.gotit and st.session_state.submitted == False:
|
| 184 |
form()
|
| 185 |
|
|
|
|
| 191 |
@st.dialog('Submit conversation')
|
| 192 |
def submit():
|
| 193 |
st.markdown("You must answer all questions marked with a ❗ to submit.")
|
|
|
|
| 194 |
if st.query_params["p"] != "n":
|
| 195 |
st.slider('❗ How would you rate the conversation on a scale from *Terrible* to *Perfect*?', 0, 100, format="", key="score", value=50)
|
| 196 |
st.slider('❗ How personalized did the conversation feel, on a scale from *Not at all* to *Extremely personalized*?', 0, 100, format="", key="personalization_score", value=50)
|
| 197 |
st.slider('❗ How knowledgeable do you feel the chatbot was, on a scale from *Not at all* to *Extremely knowledgeable*?', 0, 100, format="", key="knowledge_score", value=50)
|
| 198 |
else:
|
| 199 |
+
st.session_state.score = 0
|
| 200 |
+
st.session_state.personalization_score = 0
|
| 201 |
+
st.session_state.knowledge_score = 0
|
| 202 |
|
| 203 |
st.text_area('Any feedback?',key="feedback")
|
| 204 |
+
if st.button('Submit', key=None, help=None, use_container_width=True, disabled=st.session_state.score==50 or st.session_state.personalization_score==50):
|
|
|
|
|
|
|
| 205 |
keys = [
|
| 206 |
+
"user_id", "messages",
|
| 207 |
+
"score", "personalization_score", "knowledge_score",
|
| 208 |
+
"model", "feedback",
|
| 209 |
+
"age", "gender", "education", "residence", "property", "politics",
|
| 210 |
+
"climate_actions", "impact_open",
|
| 211 |
+
"recycling", "ev", "fossil", "aerosol", "diet",
|
| 212 |
+
"inserted", "start_time",
|
| 213 |
+
"convo_start_time"
|
| 214 |
+
]
|
| 215 |
|
| 216 |
user_data = {key: st.session_state[key] for key in keys}
|
| 217 |
+
user_data["condition"] = {st.query_params['p']}
|
| 218 |
user_data["submission_time"] = datetime.now()
|
| 219 |
|
| 220 |
from pymongo.mongo_client import MongoClient
|
|
|
|
| 227 |
|
| 228 |
st.success('**Your conversation has been submitted! Please proceed with the survey.**', icon="✅")
|
| 229 |
|
| 230 |
+
time.sleep(10)
|
| 231 |
setup_messages()
|
| 232 |
st.rerun()
|
| 233 |
|
|
|
|
| 241 |
|
| 242 |
elif st.query_params["p"] == "n":
|
| 243 |
st.markdown("""
|
| 244 |
+
You have not been selected to have a conversation with the chatbot.
|
| 245 |
+
|
| 246 |
❗ **Please press *End Conversation* to submit your data and proceed with the survey. You have to submit to receive compensation.**
|
| 247 |
""")
|
| 248 |
columns = st.columns((1,1,1))
|
knowledge.txt
CHANGED
|
@@ -21,7 +21,7 @@ Ordered from highest impact (mitigation potential close to 1.5 tCO2eq/cap) to lo
|
|
| 21 |
14. Recycling
|
| 22 |
|
| 23 |
This knowledge come from a study conducted by Ivanova et al.:
|
| 24 |
-
Ivanova, D., Barrett, J., Wiedenhofer, D., Macura, B., Callaghan, M., & Creutzig, F. (2020). Quantifying the potential for climate change mitigation of consumption options. Environmental Research Letters, 15(9), 093001.
|
| 25 |
|
| 26 |
Study Abstract:
|
| 27 |
|
|
|
|
| 21 |
14. Recycling
|
| 22 |
|
| 23 |
This knowledge come from a study conducted by Ivanova et al.:
|
| 24 |
+
Ivanova, D., Barrett, J., Wiedenhofer, D., Macura, B., Callaghan, M., & Creutzig, F. (2020). Quantifying the potential for climate change mitigation of consumption options. Environmental Research Letters, 15(9), 093001. doi.org/10.1088/1748-9326/ab8589
|
| 25 |
|
| 26 |
Study Abstract:
|
| 27 |
|
personalization.txt
CHANGED
|
@@ -21,6 +21,9 @@ Most Effective Climate Action:
|
|
| 21 |
Current Climate Actions:
|
| 22 |
- Question: 'Do you take any actions with the aim of reducing your carbon emissions and reducing your contribution to climate change?'
|
| 23 |
- User Response: [CLIMATE_ACTIONS]
|
|
|
|
|
|
|
|
|
|
| 24 |
Electric Vehicles:
|
| 25 |
- Statement: 'Electric vehicles don’t have enough range to handle daily travel demands.'
|
| 26 |
- User Response: [EV]
|
|
@@ -30,11 +33,8 @@ Diet:
|
|
| 30 |
Fossil Fuel Industry:
|
| 31 |
- Statement: 'The fossil fuel industry is trying to shift the blame away from themselves by emphasizing the importance of individual climate action.'
|
| 32 |
- User Response: [FOSSIL]
|
| 33 |
-
Recycling:
|
| 34 |
-
- Question: What percentage of plastic produced gets recycled?
|
| 35 |
-
- User Response: [RECYCLING]%
|
| 36 |
Aerosols:
|
| 37 |
-
-
|
| 38 |
- User Response: [AEROSOL]
|
| 39 |
|
| 40 |
# Your Expertise
|
|
@@ -58,7 +58,7 @@ Ordered from highest impact (mitigation potential close to 1.5 tCO2eq/cap) to lo
|
|
| 58 |
14. Recycling
|
| 59 |
|
| 60 |
This knowledge come from a study conducted by Ivanova et al.:
|
| 61 |
-
Ivanova, D., Barrett, J., Wiedenhofer, D., Macura, B., Callaghan, M., & Creutzig, F. (2020). Quantifying the potential for climate change mitigation of consumption options. Environmental Research Letters, 15(9), 093001.
|
| 62 |
|
| 63 |
Study Abstract:
|
| 64 |
|
|
|
|
| 21 |
Current Climate Actions:
|
| 22 |
- Question: 'Do you take any actions with the aim of reducing your carbon emissions and reducing your contribution to climate change?'
|
| 23 |
- User Response: [CLIMATE_ACTIONS]
|
| 24 |
+
Recycling:
|
| 25 |
+
- Question: 'What percentage of plastic produced gets recycled globally?'
|
| 26 |
+
- User Response: [RECYCLING]%
|
| 27 |
Electric Vehicles:
|
| 28 |
- Statement: 'Electric vehicles don’t have enough range to handle daily travel demands.'
|
| 29 |
- User Response: [EV]
|
|
|
|
| 33 |
Fossil Fuel Industry:
|
| 34 |
- Statement: 'The fossil fuel industry is trying to shift the blame away from themselves by emphasizing the importance of individual climate action.'
|
| 35 |
- User Response: [FOSSIL]
|
|
|
|
|
|
|
|
|
|
| 36 |
Aerosols:
|
| 37 |
+
- Statement: 'The use of aerosol spray cans is a major cause of climate change.'
|
| 38 |
- User Response: [AEROSOL]
|
| 39 |
|
| 40 |
# Your Expertise
|
|
|
|
| 58 |
14. Recycling
|
| 59 |
|
| 60 |
This knowledge come from a study conducted by Ivanova et al.:
|
| 61 |
+
Ivanova, D., Barrett, J., Wiedenhofer, D., Macura, B., Callaghan, M., & Creutzig, F. (2020). Quantifying the potential for climate change mitigation of consumption options. Environmental Research Letters, 15(9), 093001. doi.org/10.1088/1748-9326/ab8589
|
| 62 |
|
| 63 |
Study Abstract:
|
| 64 |
|