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,127 +749,118 @@ 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 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 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: 1px !important;
|
| 825 |
-
}}
|
| 826 |
-
div.stButton > button[key^="streamlit-btn-{key}-"] {{
|
| 827 |
-
width: 12px !important;
|
| 828 |
-
height: 12px !important;
|
| 829 |
-
font-size: 10px !important;
|
| 830 |
-
}}
|
| 831 |
-
}}
|
| 832 |
-
</style>
|
| 833 |
-
""",
|
| 834 |
-
unsafe_allow_html=True
|
| 835 |
-
)
|
| 836 |
|
| 837 |
-
|
| 838 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 839 |
|
| 840 |
-
#
|
| 841 |
-
|
| 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 |
-
|
| 849 |
-
|
| 850 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 851 |
if st.button(
|
| 852 |
-
|
| 853 |
-
key=f"
|
| 854 |
-
|
|
|
|
| 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.
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
|
|
|
|
|
|
|
|
|
| 869 |
|
| 870 |
-
st.markdown(
|
| 871 |
|
| 872 |
-
return st.session_state.get(key)
|
| 873 |
def create_ride_map():
|
| 874 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
| 875 |
# نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
|
|
|
|
| 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 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
|
| 752 |
+
# استایلدهی با HTML - کاملاً ایزوله شده
|
| 753 |
+
st.markdown(f"""
|
| 754 |
+
<style>
|
| 755 |
+
/* ریست کامل برای دکمههای لیکرت */
|
| 756 |
+
.likert-scale-container .stButton > button {{
|
| 757 |
+
all: unset !important;
|
| 758 |
+
min-width: 0 !important;
|
| 759 |
+
min-height: 0 !important;
|
| 760 |
+
padding: 0 !important;
|
| 761 |
+
margin: 0 2px !important;
|
| 762 |
+
border: none !important;
|
| 763 |
+
background: none !important;
|
| 764 |
+
box-shadow: none !important;
|
| 765 |
+
}}
|
| 766 |
+
|
| 767 |
+
/* استایل دکمههای دایرهای */
|
| 768 |
+
.likert-btn {{
|
| 769 |
+
width: 30px !important;
|
| 770 |
+
height: 30px !important;
|
| 771 |
+
border-radius: 50% !important;
|
| 772 |
+
border: 2px solid #6a0dad !important;
|
| 773 |
+
background: white !important;
|
| 774 |
+
display: flex !important;
|
| 775 |
+
align-items: center !important;
|
| 776 |
+
justify-content: center !important;
|
| 777 |
+
cursor: pointer !important;
|
| 778 |
+
transition: all 0.2s !important;
|
| 779 |
+
font-size: 0 !important; /* مخفی کردن عدد */
|
| 780 |
+
}}
|
| 781 |
+
|
| 782 |
+
/* حالت انتخاب شده */
|
| 783 |
+
.likert-btn.selected {{
|
| 784 |
+
background: #6a0dad !important;
|
| 785 |
+
}}
|
| 786 |
+
|
| 787 |
+
/* حالت hover */
|
| 788 |
+
.likert-btn:hover {{
|
| 789 |
+
background: #f0e6ff !important;
|
| 790 |
+
transform: scale(1.1) !important;
|
| 791 |
+
}}
|
| 792 |
+
|
| 793 |
+
/* مخفی کردن متن دکمه */
|
| 794 |
+
.likert-btn > div > p {{
|
| 795 |
+
display: none !important;
|
| 796 |
+
}}
|
| 797 |
+
|
| 798 |
+
/* لیبلها در یک ردیف */
|
| 799 |
+
.likert-labels {{
|
| 800 |
+
display: flex !important;
|
| 801 |
+
justify-content: space-between !important;
|
| 802 |
+
margin-bottom: 5px !important;
|
| 803 |
+
direction: rtl !important;
|
| 804 |
+
}}
|
| 805 |
+
|
| 806 |
+
/* کانتینر اصلی */
|
| 807 |
+
.likert-container {{
|
| 808 |
+
width: 100% !important;
|
| 809 |
+
margin: 0 auto !important;
|
| 810 |
+
padding: 0 10px !important;
|
| 811 |
+
}}
|
| 812 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
|
| 814 |
+
<div class="likert-container">
|
| 815 |
+
<div class="likert-question">{question}</div>
|
| 816 |
+
<div class="likert-labels">
|
| 817 |
+
<span>{labels[1]}</span>
|
| 818 |
+
<span>{labels[0]}</span>
|
| 819 |
+
</div>
|
| 820 |
+
<div class="likert-scale-container">
|
| 821 |
+
""", unsafe_allow_html=True)
|
| 822 |
|
| 823 |
+
# ایجاد دکمهها با HTML
|
| 824 |
+
btn_html = "<div style='display: flex; justify-content: center; gap: 5px; margin-bottom: 10px;'>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
for i in range(scale):
|
| 826 |
+
value = scale - i # 7 تا 1
|
| 827 |
+
is_selected = st.session_state.get(key) == value
|
| 828 |
+
btn_html += f"""
|
| 829 |
+
<button class="likert-btn {'selected' if is_selected else ''}"
|
| 830 |
+
onclick="parent.document.querySelector('button[data-testid=\"baseButton-secondary\"][value=\"{value}\"]').click()">
|
| 831 |
+
<div><p>{value}</p></div>
|
| 832 |
+
</button>
|
| 833 |
+
"""
|
| 834 |
+
btn_html += "</div>"
|
| 835 |
+
|
| 836 |
+
components.html(btn_html, height=50)
|
| 837 |
+
|
| 838 |
+
# دکمههای واقعی (مخفی)
|
| 839 |
+
btn_cols = st.columns(scale)
|
| 840 |
+
for i in range(scale):
|
| 841 |
+
with btn_cols[i]:
|
| 842 |
+
value = scale - i
|
| 843 |
if st.button(
|
| 844 |
+
str(value),
|
| 845 |
+
key=f"{key}_btn_{value}",
|
| 846 |
+
type="primary" if st.session_state.get(key) == value else "secondary",
|
| 847 |
+
on_click=lambda v=value: st.session_state.update({key: v})
|
| 848 |
):
|
| 849 |
st.session_state[key] = value
|
| 850 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 851 |
|
| 852 |
+
# نمایش پاسخ انتخاب شده
|
| 853 |
+
if st.session_state.get(key) is not None:
|
| 854 |
+
st.markdown(
|
| 855 |
+
f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:5px;'>"
|
| 856 |
+
f"پاسخ شما: {st.session_state[key]}"
|
| 857 |
+
f"</div>",
|
| 858 |
+
unsafe_allow_html=True
|
| 859 |
+
)
|
| 860 |
|
| 861 |
+
st.markdown("</div>", unsafe_allow_html=True) # بستن کانتینر
|
| 862 |
|
| 863 |
+
return st.session_state.get(key)
|
| 864 |
def create_ride_map():
|
| 865 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
| 866 |
# نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
|