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,204 +749,126 @@ def enhanced_likert_scale(question_data):
|
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
|
| 752 |
-
# استایلدهی
|
| 753 |
-
|
| 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 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
text-align: center !important;
|
| 841 |
-
color: #6a0dad !important;
|
| 842 |
-
font-weight: bold !important;
|
| 843 |
-
margin-top: 10px !important;
|
| 844 |
-
font-size: 16px !important;
|
| 845 |
-
}}
|
| 846 |
-
</style>
|
| 847 |
-
<div class="likert-container">
|
| 848 |
-
<div class="likert-question">{question}</div>
|
| 849 |
-
<div class="likert-labels">
|
| 850 |
-
<span style="text-align:right">{labels[0]}</span>
|
| 851 |
-
<span style="text-align:left">{labels[1]}</span>
|
| 852 |
-
</div>
|
| 853 |
-
<div class="likert-buttons" id="likert-buttons-{key}">
|
| 854 |
-
"""
|
| 855 |
|
| 856 |
-
# م
|
| 857 |
-
|
| 858 |
-
gap = 8
|
| 859 |
-
total_width = scale * button_width + (scale - 1) * gap
|
| 860 |
-
start_x = -total_width / 2 # برای وسطچین کردن دکمهها
|
| 861 |
|
| 862 |
-
#
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
html_content += f"""
|
| 868 |
-
<button class="likert-btn {'selected' if is_selected else ''}"
|
| 869 |
-
style="left: calc(50% + {x_position}px); top: 0;"
|
| 870 |
-
onclick="document.getElementById('streamlit-btn-{key}-{value}').click()">
|
| 871 |
-
{'•' if is_selected else '○'}
|
| 872 |
-
</button>
|
| 873 |
-
"""
|
| 874 |
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
</
|
| 890 |
-
"""
|
| 891 |
|
| 892 |
-
#
|
| 893 |
-
|
|
|
|
|
|
|
|
|
|
| 894 |
|
| 895 |
-
# ایجاد دکمههای Streamlit
|
| 896 |
-
st.markdown('<div style="display: flex; justify-content: center; gap: 8px; margin: 0; padding: 0;">', unsafe_allow_html=True)
|
| 897 |
-
for i in range(scale):
|
| 898 |
-
value = scale - i # 7 تا 1
|
| 899 |
-
st.markdown(
|
| 900 |
-
f"""
|
| 901 |
-
<style>
|
| 902 |
-
.likert-streamlit-btn-container-{key}-{value} {{
|
| 903 |
-
position: relative !important;
|
| 904 |
-
width: 40px !important;
|
| 905 |
-
height: 40px !important;
|
| 906 |
-
margin: 0 !important;
|
| 907 |
-
padding: 0 !important;
|
| 908 |
-
}}
|
| 909 |
-
#streamlit-btn-{key}-{value} {{
|
| 910 |
-
width: 40px !important;
|
| 911 |
-
height: 40px !important;
|
| 912 |
-
opacity: 0 !important;
|
| 913 |
-
position: absolute !important;
|
| 914 |
-
top: 0 !important;
|
| 915 |
-
left: 0 !important;
|
| 916 |
-
margin: 0 !important;
|
| 917 |
-
padding: 0 !important;
|
| 918 |
-
border: none !important;
|
| 919 |
-
background: white !important;
|
| 920 |
-
z-index: 1 !important;
|
| 921 |
-
}}
|
| 922 |
-
#streamlit-btn-{key}-{value}:hover,
|
| 923 |
-
#streamlit-btn-{key}-{value}:focus,
|
| 924 |
-
#streamlit-btn-{key}-{value}:active {{
|
| 925 |
-
border: none !important;
|
| 926 |
-
background: white !important;
|
| 927 |
-
}}
|
| 928 |
-
</style>
|
| 929 |
-
<div class="likert-streamlit-btn-container-{key}-{value}"></div>
|
| 930 |
-
""",
|
| 931 |
-
unsafe_allow_html=True
|
| 932 |
-
)
|
| 933 |
-
if st.button(
|
| 934 |
-
"•" if st.session_state[key] == value else "○",
|
| 935 |
-
key=f"streamlit-btn-{key}-{value}",
|
| 936 |
-
help=str(value),
|
| 937 |
-
type="secondary"
|
| 938 |
-
):
|
| 939 |
-
st.session_state[key] = value
|
| 940 |
-
# آپدیت دکمههای HTML با JavaScript
|
| 941 |
-
st.markdown(
|
| 942 |
-
f"""
|
| 943 |
-
<script>
|
| 944 |
-
updateLikertSelection('{key}', {value});
|
| 945 |
-
</script>
|
| 946 |
-
""",
|
| 947 |
-
unsafe_allow_html=True
|
| 948 |
-
)
|
| 949 |
-
st.rerun()
|
| 950 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 951 |
|
| 952 |
return st.session_state.get(key)
|
|
|
|
| 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>
|
| 756 |
+
/* استایل کانتینر لیکرت */
|
| 757 |
+
.likert-container {{
|
| 758 |
+
font-family: 'B Nazanin', Arial, sans-serif !important;
|
| 759 |
+
direction: rtl !important;
|
| 760 |
+
text-align: center !important;
|
| 761 |
+
margin: 0 !important;
|
| 762 |
+
}}
|
| 763 |
+
.likert-question {{
|
| 764 |
+
font-size: 18px !important;
|
| 765 |
+
font-weight: bold !important;
|
| 766 |
+
margin-bottom: 15px !important;
|
| 767 |
+
color: #333333 !important;
|
| 768 |
+
}}
|
| 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: 8px !important;
|
| 781 |
+
flex-wrap: wrap !important;
|
| 782 |
+
margin: 0 !important;
|
| 783 |
+
padding: 0 !important;
|
| 784 |
+
}}
|
| 785 |
+
/* استایل دکمههای Streamlit */
|
| 786 |
+
div.stButton > button[key^="streamlit-btn-{key}-"] {{
|
| 787 |
+
width: 40px !important;
|
| 788 |
+
height: 40px !important;
|
| 789 |
+
border-radius: 50% !important;
|
| 790 |
+
border: 2px solid #6a0dad !important;
|
| 791 |
+
background: white !important;
|
| 792 |
+
display: flex !important;
|
| 793 |
+
align-items: center !important;
|
| 794 |
+
justify-content: center !important;
|
| 795 |
+
font-size: 18px !important;
|
| 796 |
+
color: #6a0dad !important;
|
| 797 |
+
padding: 0 !important;
|
| 798 |
+
margin: 0 !important;
|
| 799 |
+
transition: all 0.3s ease !important;
|
| 800 |
+
}}
|
| 801 |
+
div.stButton > button[key^="streamlit-btn-{key}-"]:hover {{
|
| 802 |
+
background: #f0e6ff !important;
|
| 803 |
+
transform: scale(1.1) !important;
|
| 804 |
+
}}
|
| 805 |
+
div.stButton > button[key^="streamlit-btn-{key}-"]:focus,
|
| 806 |
+
div.stButton > button[key^="streamlit-btn-{key}-"]:active {{
|
| 807 |
+
background: #6a0dad !important;
|
| 808 |
+
color: white !important;
|
| 809 |
+
box-shadow: 0 0 10px rgba(106, 13, 173, 0.5) !important;
|
| 810 |
+
}}
|
| 811 |
+
/* استایل دکمه انتخابشده */
|
| 812 |
+
div.stButton > button[key="streamlit-btn-{key}-{st.session_state[key] if st.session_state[key] else 'none'}"] {{
|
| 813 |
+
background: #6a0dad !important;
|
| 814 |
+
color: white !important;
|
| 815 |
+
box-shadow: 0 0 10px rgba(106, 13, 173, 0.5) !important;
|
| 816 |
+
}}
|
| 817 |
+
/* استایل پاسخ */
|
| 818 |
+
.likert-response {{
|
| 819 |
+
text-align: center !important;
|
| 820 |
+
color: #6a0dad !important;
|
| 821 |
+
font-weight: bold !important;
|
| 822 |
+
margin-top: 10px !important;
|
| 823 |
+
font-size: 16px !important;
|
| 824 |
+
}}
|
| 825 |
+
/* ریسپانسیو کردن */
|
| 826 |
+
@media (max-width: 600px) {{
|
| 827 |
+
.likert-buttons {{
|
| 828 |
+
gap: 4px !important;
|
| 829 |
+
}}
|
| 830 |
+
div.stButton > button[key^="streamlit-btn-{key}-"] {{
|
| 831 |
+
width: 36px !important;
|
| 832 |
+
height: 36px !important;
|
| 833 |
+
font-size: 16px !important;
|
| 834 |
+
}}
|
| 835 |
+
}}
|
| 836 |
+
</style>
|
| 837 |
+
""",
|
| 838 |
+
unsafe_allow_html=True
|
| 839 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
|
| 841 |
+
# نمایش سوال
|
| 842 |
+
st.markdown(f'<div class="likert-container"><div class="likert-question">{question}</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
| 843 |
|
| 844 |
+
# نمایش لیبلها
|
| 845 |
+
st.markdown(
|
| 846 |
+
f'<div class="likert-labels"><span style="text-align:right">{labels[0]}</span><span style="text-align:left">{labels[1]}</span></div>',
|
| 847 |
+
unsafe_allow_html=True
|
| 848 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
|
| 850 |
+
# نمایش دکمهها در یک ردیف
|
| 851 |
+
st.markdown('<div class="likert-buttons">', unsafe_allow_html=True)
|
| 852 |
+
cols = st.columns(scale)
|
| 853 |
+
for i in range(scale):
|
| 854 |
+
with cols[i]:
|
| 855 |
+
value = scale - i # 7 تا 1
|
| 856 |
+
symbol = "•" if st.session_state[key] == value else "○"
|
| 857 |
+
if st.button(
|
| 858 |
+
symbol,
|
| 859 |
+
key=f"streamlit-btn-{key}-{value}",
|
| 860 |
+
help=str(value)
|
| 861 |
+
):
|
| 862 |
+
st.session_state[key] = value
|
| 863 |
+
st.rerun()
|
| 864 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
| 865 |
|
| 866 |
+
# نمایش پاسخ
|
| 867 |
+
st.markdown(
|
| 868 |
+
f'<div class="likert-response">پاسخ شما: {st.session_state[key] or "هیچکدام"}</div>',
|
| 869 |
+
unsafe_allow_html=True
|
| 870 |
+
)
|
| 871 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 873 |
|
| 874 |
return st.session_state.get(key)
|