Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,7 +739,7 @@ h3 {
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
-
"""لیکرت اسکیل با
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
@@ -749,7 +749,7 @@ def enhanced_likert_scale(question_data):
|
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
|
| 752 |
-
# استایلدهی سفارشی برای دکمههای
|
| 753 |
st.markdown(
|
| 754 |
f"""
|
| 755 |
<style>
|
|
@@ -769,23 +769,22 @@ def enhanced_likert_scale(question_data):
|
|
| 769 |
.likert-labels {{
|
| 770 |
display: flex !important;
|
| 771 |
justify-content: space-between !important;
|
| 772 |
-
align-items: center !important;
|
| 773 |
font-size: 14px !important;
|
| 774 |
margin-bottom: 10px !important;
|
| 775 |
color: #666666 !important;
|
| 776 |
}}
|
| 777 |
/* استایل ردیف دکمهها */
|
| 778 |
-
.
|
| 779 |
display: flex !important;
|
| 780 |
justify-content: center !important;
|
| 781 |
gap: 4px !important;
|
| 782 |
-
flex-wrap:
|
| 783 |
margin: 0 !important;
|
| 784 |
padding: 0 !important;
|
| 785 |
align-items: center !important;
|
| 786 |
}}
|
| 787 |
-
/* استایل دکمههای
|
| 788 |
-
.
|
| 789 |
width: 20px !important;
|
| 790 |
height: 20px !important;
|
| 791 |
border-radius: 50% !important;
|
|
@@ -797,38 +796,38 @@ def enhanced_likert_scale(question_data):
|
|
| 797 |
margin: 0 !important;
|
| 798 |
box-shadow: none !important;
|
| 799 |
outline: none !important;
|
| 800 |
-
line-height: 1 !important;
|
| 801 |
-
display: flex !important;
|
| 802 |
-
align-items: center !important;
|
| 803 |
-
justify-content: center !important;
|
| 804 |
}}
|
| 805 |
-
.
|
| 806 |
background: #e0e0e0 !important;
|
| 807 |
}}
|
| 808 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 809 |
background: black !important;
|
| 810 |
color: white !important;
|
| 811 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 812 |
/* ریسپانسیو کردن */
|
| 813 |
@media (max-width: 600px) {{
|
| 814 |
-
.
|
| 815 |
gap: 2px !important;
|
| 816 |
}}
|
| 817 |
-
.
|
| 818 |
width: 18px !important;
|
| 819 |
height: 18px !important;
|
| 820 |
font-size: 12px !important;
|
| 821 |
}}
|
| 822 |
-
.likert-labels {{
|
| 823 |
-
font-size: 12px !important;
|
| 824 |
-
}}
|
| 825 |
-
}}
|
| 826 |
-
/* حذف استایلهای پیشفرض Streamlit */
|
| 827 |
-
.stRadio > div > label > div > div > div {{
|
| 828 |
-
border: none !important;
|
| 829 |
-
box-shadow: none !important;
|
| 830 |
-
outline: none !important;
|
| 831 |
-
background: transparent !important;
|
| 832 |
}}
|
| 833 |
</style>
|
| 834 |
""",
|
|
@@ -838,27 +837,29 @@ def enhanced_likert_scale(question_data):
|
|
| 838 |
# نمایش سوال
|
| 839 |
st.markdown(f'<div class="likert-container"><div class="likert-question">{question}</div>', unsafe_allow_html=True)
|
| 840 |
|
| 841 |
-
# نمایش لیبلها
|
| 842 |
-
st.markdown(
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
# دکمهها با st.radio
|
| 846 |
-
options = [str(i) for i in range(1, scale + 1)]
|
| 847 |
-
symbols = ["○"] * scale
|
| 848 |
-
selected_index = options.index(str(st.session_state.get(key, 1))) if st.session_state.get(key) else 0
|
| 849 |
-
value = st.radio(
|
| 850 |
-
"",
|
| 851 |
-
options=options,
|
| 852 |
-
format_func=lambda x: "•" if options.index(x) == selected_index else "○",
|
| 853 |
-
key=f"radio-{key}",
|
| 854 |
-
index=selected_index,
|
| 855 |
-
horizontal=True
|
| 856 |
)
|
| 857 |
-
st.
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 862 |
|
| 863 |
# نمایش پاسخ
|
| 864 |
st.markdown(
|
|
@@ -868,9 +869,7 @@ def enhanced_likert_scale(question_data):
|
|
| 868 |
|
| 869 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 870 |
|
| 871 |
-
return st.session_state.get(key)
|
| 872 |
-
|
| 873 |
-
|
| 874 |
def create_ride_map():
|
| 875 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
| 876 |
# نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
|
|
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
+
"""لیکرت اسکیل فقط با فیچرهای Streamlit و دکمههای دایرهای ریسپانسیو"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
|
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
|
| 752 |
+
# استایلدهی سفارشی برای دکمههای Streamlit
|
| 753 |
st.markdown(
|
| 754 |
f"""
|
| 755 |
<style>
|
|
|
|
| 769 |
.likert-labels {{
|
| 770 |
display: flex !important;
|
| 771 |
justify-content: space-between !important;
|
|
|
|
| 772 |
font-size: 14px !important;
|
| 773 |
margin-bottom: 10px !important;
|
| 774 |
color: #666666 !important;
|
| 775 |
}}
|
| 776 |
/* استایل ردیف دکمهها */
|
| 777 |
+
.likert-buttons {{
|
| 778 |
display: flex !important;
|
| 779 |
justify-content: center !important;
|
| 780 |
gap: 4px !important;
|
| 781 |
+
flex-wrap: wrap !important;
|
| 782 |
margin: 0 !important;
|
| 783 |
padding: 0 !important;
|
| 784 |
align-items: center !important;
|
| 785 |
}}
|
| 786 |
+
/* استایل دکمههای Streamlit */
|
| 787 |
+
div.stButton > button[key^="streamlit-btn-{key}-"] {{
|
| 788 |
width: 20px !important;
|
| 789 |
height: 20px !important;
|
| 790 |
border-radius: 50% !important;
|
|
|
|
| 796 |
margin: 0 !important;
|
| 797 |
box-shadow: none !important;
|
| 798 |
outline: none !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
}}
|
| 800 |
+
div.stButton > button[key^="streamlit-btn-{key}-"]:hover {{
|
| 801 |
background: #e0e0e0 !important;
|
| 802 |
}}
|
| 803 |
+
div.stButton > button[key^="streamlit-btn-{key}-"]:focus,
|
| 804 |
+
div.stButton > button[key^="streamlit-btn-{key}-"]:active {{
|
| 805 |
+
background: black !important;
|
| 806 |
+
color: white !important;
|
| 807 |
+
}}
|
| 808 |
+
/* استایل دکمه انتخابشده */
|
| 809 |
+
div.stButton > button[key="streamlit-btn-{key}-{st.session_state[key] if st.session_state[key] else 'none'}"] {{
|
| 810 |
background: black !important;
|
| 811 |
color: white !important;
|
| 812 |
}}
|
| 813 |
+
/* استایل پاسخ */
|
| 814 |
+
.likert-response {{
|
| 815 |
+
text-align: center !important;
|
| 816 |
+
color: #6a0dad !important;
|
| 817 |
+
font-weight: bold !important;
|
| 818 |
+
margin-top: 10px !important;
|
| 819 |
+
font-size: 16px !important;
|
| 820 |
+
}}
|
| 821 |
/* ریسپانسیو کردن */
|
| 822 |
@media (max-width: 600px) {{
|
| 823 |
+
.likert-buttons {{
|
| 824 |
gap: 2px !important;
|
| 825 |
}}
|
| 826 |
+
div.stButton > button[key^="streamlit-btn-{key}-"] {{
|
| 827 |
width: 18px !important;
|
| 828 |
height: 18px !important;
|
| 829 |
font-size: 12px !important;
|
| 830 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 831 |
}}
|
| 832 |
</style>
|
| 833 |
""",
|
|
|
|
| 837 |
# نمایش سوال
|
| 838 |
st.markdown(f'<div class="likert-container"><div class="likert-question">{question}</div>', unsafe_allow_html=True)
|
| 839 |
|
| 840 |
+
# نمایش لیبلها و دکمهها تو یه ردیف
|
| 841 |
+
st.markdown(
|
| 842 |
+
f'<div class="likert-labels"><span style="text-align:right">{labels[0]}</span>',
|
| 843 |
+
unsafe_allow_html=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 844 |
)
|
| 845 |
+
st.markdown('<div class="likert-buttons">', unsafe_allow_html=True)
|
| 846 |
+
cols = st.columns(scale)
|
| 847 |
+
for i in range(scale):
|
| 848 |
+
with cols[i]:
|
| 849 |
+
value = scale - i # 7 تا 1
|
| 850 |
+
symbol = "•" if st.session_state[key] == value else "○"
|
| 851 |
+
if st.button(
|
| 852 |
+
symbol,
|
| 853 |
+
key=f"streamlit-btn-{key}-{value}",
|
| 854 |
+
help=str(value)
|
| 855 |
+
):
|
| 856 |
+
st.session_state[key] = value
|
| 857 |
+
st.rerun()
|
| 858 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 859 |
+
st.markdown(
|
| 860 |
+
f'<span style="text-align:left">{labels[1]}</span></div>',
|
| 861 |
+
unsafe_allow_html=True
|
| 862 |
+
)
|
| 863 |
|
| 864 |
# نمایش پاسخ
|
| 865 |
st.markdown(
|
|
|
|
| 869 |
|
| 870 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 871 |
|
| 872 |
+
return st.session_state.get(key)
|
|
|
|
|
|
|
| 873 |
def create_ride_map():
|
| 874 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
| 875 |
# نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
|