Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,86 +739,42 @@ h3 {
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
-
"""لیکرت اسکیل با ترتیب 7 (کاملاً م
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
| 746 |
labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
|
| 747 |
|
| 748 |
-
# م
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
.likert-container {{
|
| 756 |
-
direction: rtl;
|
| 757 |
-
margin-bottom: 25px;
|
| 758 |
-
}}
|
| 759 |
-
.likert-question {{
|
| 760 |
-
font-family: 'B Nazanin';
|
| 761 |
-
font-size: 18px;
|
| 762 |
-
font-weight: bold;
|
| 763 |
-
text-align: center;
|
| 764 |
-
margin-bottom: 15px;
|
| 765 |
-
color: #333;
|
| 766 |
-
}}
|
| 767 |
-
.likert-labels {{
|
| 768 |
-
display: flex;
|
| 769 |
-
justify-content: space-between;
|
| 770 |
-
margin-bottom: 8px;
|
| 771 |
-
font-family: 'B Nazanin';
|
| 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>
|
| 801 |
-
<div class="likert-labels">
|
| 802 |
-
<span>{labels[1]}</span>
|
| 803 |
-
<span>{labels[0]}</span>
|
| 804 |
-
</div>
|
| 805 |
-
</div>
|
| 806 |
-
""", unsafe_allow_html=True)
|
| 807 |
|
|
|
|
| 808 |
btn_cols = st.columns(scale)
|
| 809 |
for i in range(scale):
|
| 810 |
-
with btn_cols[i]:
|
| 811 |
value = scale - i # مقدار از 7 به 1
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 819 |
|
| 820 |
-
# نمایش پاسخ
|
| 821 |
-
if st.session_state.get(key):
|
| 822 |
st.markdown(
|
| 823 |
f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:10px;'>"
|
| 824 |
f"پاسخ شما: {st.session_state[key]}"
|
|
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
+
"""لیکرت اسکیل با ترتیب 7 (راست) تا 1 (چپ) کاملاً عملیاتی"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
| 746 |
labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
|
| 747 |
|
| 748 |
+
# نمایش سوال و برچسبها
|
| 749 |
+
st.markdown(f"**{question}**")
|
| 750 |
+
cols = st.columns([1] + [0.5]*(scale-2) + [1])
|
| 751 |
+
with cols[0]:
|
| 752 |
+
st.markdown(f"<div style='text-align:right;'>{labels[0]}</div>", unsafe_allow_html=True)
|
| 753 |
+
with cols[-1]:
|
| 754 |
+
st.markdown(f"<div style='text-align:left;'>{labels[1]}</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
|
| 756 |
+
# ایجاد دکمهها از راست به چپ (7 تا 1)
|
| 757 |
btn_cols = st.columns(scale)
|
| 758 |
for i in range(scale):
|
| 759 |
+
with btn_cols[i]:
|
| 760 |
value = scale - i # مقدار از 7 به 1
|
| 761 |
+
is_selected = st.session_state.get(key) == value
|
| 762 |
+
btn_style = (
|
| 763 |
+
"background-color: #6a0dad; color: white;"
|
| 764 |
+
if is_selected
|
| 765 |
+
else "background-color: white; color: #6a0dad;"
|
| 766 |
+
)
|
| 767 |
+
st.markdown(
|
| 768 |
+
f"<div style='{btn_style} border: 2px solid #6a0dad; border-radius: 50%; "
|
| 769 |
+
f"width: 40px; height: 40px; display: flex; align-items: center; "
|
| 770 |
+
f"justify-content: center; cursor: pointer; margin: 0 auto;' "
|
| 771 |
+
f"onclick='window.parent.postMessage({{type: \"streamlit:setComponentValue\", "
|
| 772 |
+
f"key: \"{key}\", value: {value}}}, \"*\")'>{value}</div>",
|
| 773 |
+
unsafe_allow_html=True
|
| 774 |
+
)
|
| 775 |
|
| 776 |
+
# نمایش پاسخ انتخاب شده
|
| 777 |
+
if st.session_state.get(key) is not None:
|
| 778 |
st.markdown(
|
| 779 |
f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:10px;'>"
|
| 780 |
f"پاسخ شما: {st.session_state[key]}"
|