Spaces:
Sleeping
Sleeping
Commit ·
0a6970e
1
Parent(s): d1f1fb3
Add environment page
Browse files- app.py +5 -0
- page_environment.py +38 -0
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import page_attitudes
|
|
| 4 |
import page_demographics
|
| 5 |
import page_shopping
|
| 6 |
import page_investing
|
|
|
|
| 7 |
import page_ai
|
| 8 |
import page_personas
|
| 9 |
import page_tests
|
|
@@ -43,6 +44,8 @@ if st.sidebar.button("Shopping"):
|
|
| 43 |
st.session_state['page'] = 'Shopping'
|
| 44 |
if st.sidebar.button("Investing"):
|
| 45 |
st.session_state['page'] = 'Investing'
|
|
|
|
|
|
|
| 46 |
if st.sidebar.button("AI Companion"):
|
| 47 |
st.session_state['page'] = 'AI'
|
| 48 |
if st.sidebar.button("Tests"):
|
|
@@ -66,6 +69,8 @@ elif st.session_state['page'] == 'Shopping':
|
|
| 66 |
page_shopping.show(df)
|
| 67 |
elif st.session_state['page'] == 'Investing':
|
| 68 |
page_investing.show(df)
|
|
|
|
|
|
|
| 69 |
elif st.session_state['page'] == 'AI':
|
| 70 |
page_ai.show(df)
|
| 71 |
elif st.session_state['page'] == 'Tests':
|
|
|
|
| 4 |
import page_demographics
|
| 5 |
import page_shopping
|
| 6 |
import page_investing
|
| 7 |
+
import page_environment
|
| 8 |
import page_ai
|
| 9 |
import page_personas
|
| 10 |
import page_tests
|
|
|
|
| 44 |
st.session_state['page'] = 'Shopping'
|
| 45 |
if st.sidebar.button("Investing"):
|
| 46 |
st.session_state['page'] = 'Investing'
|
| 47 |
+
if st.sidebar.button("Environment"):
|
| 48 |
+
st.session_state['page'] = 'Environment'
|
| 49 |
if st.sidebar.button("AI Companion"):
|
| 50 |
st.session_state['page'] = 'AI'
|
| 51 |
if st.sidebar.button("Tests"):
|
|
|
|
| 69 |
page_shopping.show(df)
|
| 70 |
elif st.session_state['page'] == 'Investing':
|
| 71 |
page_investing.show(df)
|
| 72 |
+
elif st.session_state['page'] == 'Environment':
|
| 73 |
+
page_environment.show(df)
|
| 74 |
elif st.session_state['page'] == 'AI':
|
| 75 |
page_ai.show(df)
|
| 76 |
elif st.session_state['page'] == 'Tests':
|
page_environment.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from matplotlib.font_manager import FontProperties
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import seaborn as sns
|
| 6 |
+
from fields.likert_fields import likert_fields
|
| 7 |
+
|
| 8 |
+
@st.cache_data
|
| 9 |
+
def show(df):
|
| 10 |
+
# Load the Chinese font
|
| 11 |
+
chinese_font = FontProperties(fname='notosans.ttf', size=12)
|
| 12 |
+
st.title("Environment")
|
| 13 |
+
|
| 14 |
+
st.markdown(
|
| 15 |
+
f"<h2 style='text-align: center;'>Ranking Experiment</h2>", unsafe_allow_html=True)
|
| 16 |
+
visualize_ecosystem_sensitivity(df, chinese_font)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def visualize_ecosystem_sensitivity(df, chinese_font):
|
| 21 |
+
|
| 22 |
+
# Field related to ecosystem sensitivity to environmental degradation
|
| 23 |
+
ecosystem_field = "你/妳覺得如何依照生態系對環境惡化的敏感度來排名?"
|
| 24 |
+
|
| 25 |
+
# Summarize the data
|
| 26 |
+
ecosystem_data = df[ecosystem_field].value_counts().head(20) # Adjust the number as needed
|
| 27 |
+
|
| 28 |
+
# Plot the data
|
| 29 |
+
plt.figure(figsize=(10, 6))
|
| 30 |
+
ecosystem_data.plot(kind='bar', color='forestgreen')
|
| 31 |
+
plt.title('Ecosystem Sensitivity to Environmental Degradation', fontproperties=chinese_font)
|
| 32 |
+
plt.xlabel('Sensitivity Ranking', fontproperties=chinese_font)
|
| 33 |
+
plt.ylabel('Number of Responses', fontproperties=chinese_font)
|
| 34 |
+
plt.xticks(rotation=45, ha='right', fontproperties=chinese_font)
|
| 35 |
+
plt.tight_layout()
|
| 36 |
+
|
| 37 |
+
# Display the plot in Streamlit
|
| 38 |
+
st.pyplot(plt)
|