Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,13 +739,13 @@ 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"]
|
| 746 |
labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
|
| 747 |
|
| 748 |
-
# مقدار
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
|
|
@@ -772,6 +772,29 @@ def enhanced_likert_scale(question_data):
|
|
| 772 |
font-size: 14px;
|
| 773 |
color: #555;
|
| 774 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
</style>
|
| 776 |
<div class="likert-container">
|
| 777 |
<div class="likert-question">{question}</div>
|
|
@@ -782,26 +805,27 @@ def enhanced_likert_scale(question_data):
|
|
| 782 |
</div>
|
| 783 |
""", unsafe_allow_html=True)
|
| 784 |
|
| 785 |
-
# ایجاد دکمههای
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
with cols[i]:
|
| 791 |
if st.button(
|
| 792 |
-
str(
|
| 793 |
-
key=f"{key}_btn_{
|
| 794 |
-
on_click=lambda v=
|
| 795 |
):
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
|
|
|
| 799 |
if st.session_state[key] is not None:
|
| 800 |
-
st.markdown(
|
| 801 |
-
|
| 802 |
-
پاسخ شما: {st.session_state[key]}
|
| 803 |
-
|
| 804 |
-
|
|
|
|
| 805 |
|
| 806 |
return st.session_state[key]
|
| 807 |
|
|
|
|
| 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"]
|
| 746 |
labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
|
| 747 |
|
| 748 |
+
# مقداردهی اولیه
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
|
|
|
|
| 772 |
font-size: 14px;
|
| 773 |
color: #555;
|
| 774 |
}}
|
| 775 |
+
.likert-btn-container {{
|
| 776 |
+
display: flex;
|
| 777 |
+
justify-content: center;
|
| 778 |
+
gap: 8px;
|
| 779 |
+
margin-bottom: 15px;
|
| 780 |
+
}}
|
| 781 |
+
.likert-btn {{
|
| 782 |
+
width: 40px;
|
| 783 |
+
height: 40px;
|
| 784 |
+
border-radius: 50%;
|
| 785 |
+
border: 2px solid #6a0dad;
|
| 786 |
+
background: { "#6a0dad" if st.session_state[key] is not None else "white" };
|
| 787 |
+
color: { "white" if st.session_state[key] is not None else "#6a0dad" };
|
| 788 |
+
font-weight: bold;
|
| 789 |
+
display: flex;
|
| 790 |
+
align-items: center;
|
| 791 |
+
justify-content: center;
|
| 792 |
+
cursor: pointer;
|
| 793 |
+
transition: all 0.3s;
|
| 794 |
+
}}
|
| 795 |
+
.likert-btn:hover {{
|
| 796 |
+
transform: scale(1.1);
|
| 797 |
+
}}
|
| 798 |
</style>
|
| 799 |
<div class="likert-container">
|
| 800 |
<div class="likert-question">{question}</div>
|
|
|
|
| 805 |
</div>
|
| 806 |
""", unsafe_allow_html=True)
|
| 807 |
|
| 808 |
+
# ایجاد دکمهها (حلقه مستقیم برای ترتیب چپ به راست)
|
| 809 |
+
btn_cols = st.columns(scale)
|
| 810 |
+
for i in range(scale):
|
| 811 |
+
with btn_cols[i]:
|
| 812 |
+
value = i+1
|
|
|
|
| 813 |
if st.button(
|
| 814 |
+
str(value),
|
| 815 |
+
key=f"{key}_btn_{value}",
|
| 816 |
+
on_click=lambda v=value: st.session_state.update({key: v})
|
| 817 |
):
|
| 818 |
+
st.session_state[key] = value
|
| 819 |
+
st.rerun()
|
| 820 |
+
|
| 821 |
+
# نمایش پاسخ انتخاب شده
|
| 822 |
if st.session_state[key] is not None:
|
| 823 |
+
st.markdown(
|
| 824 |
+
f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:10px;'>"
|
| 825 |
+
f"پاسخ شما: {st.session_state[key]}"
|
| 826 |
+
f"</div>",
|
| 827 |
+
unsafe_allow_html=True
|
| 828 |
+
)
|
| 829 |
|
| 830 |
return st.session_state[key]
|
| 831 |
|