Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -735,78 +735,139 @@ h3 {
|
|
| 735 |
line-height: 1.8 !important;
|
| 736 |
}
|
| 737 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
""", unsafe_allow_html=True)
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def custom_likert_slider(question_data):
|
| 742 |
-
"""نمایش سوال لیکرت با اسلایدر س
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
points = question_data["scale"]
|
| 746 |
labels = question_data.get("labels", ["کمترین", "بیشترین"]) # لیبلهای پیشفرض
|
| 747 |
-
|
| 748 |
# مقدار پیشفرض (وسط طیف)
|
| 749 |
default_value = (points + 1) // 2
|
| 750 |
-
|
| 751 |
-
# م
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
#
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
<
|
| 758 |
-
<div style="display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px;">
|
| 759 |
<span>{labels[0]}</span>
|
| 760 |
<span>{labels[1]}</span>
|
| 761 |
</div>
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
<div style="text-align: center; margin-top: 10px; direction: rtl;">
|
| 766 |
-
پاسخ انتخابشده: <strong><span id="output_{key}">{current_value}</span></strong>
|
| 767 |
-
</div>
|
| 768 |
-
</div>
|
| 769 |
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
key: key
|
| 781 |
-
}};
|
| 782 |
-
window.parent.postMessage(message, '*');
|
| 783 |
-
|
| 784 |
-
// دیباگ: چاپ پیام ارسالی
|
| 785 |
-
console.log('Sending to Streamlit: ', JSON.stringify(message));
|
| 786 |
-
}}
|
| 787 |
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
# دیباگ: نمایش مقادیر
|
| 801 |
-
st.write(f"Debug: کلید: {key}")
|
| 802 |
-
st.write(f"Debug: مقدار پیشفرض: {default_value}")
|
| 803 |
-
st.write(f"Debug: مقدار دریافتشده: {component_value}")
|
| 804 |
-
st.write(f"Debug: مقدار در session_state[{key}]: {st.session_state.get(key, 'هیچ')}")
|
| 805 |
|
| 806 |
# ذخیره مقدار
|
| 807 |
-
st.session_state[key] =
|
| 808 |
-
|
| 809 |
-
return component_value
|
| 810 |
|
| 811 |
def create_ride_map():
|
| 812 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
|
|
|
| 735 |
line-height: 1.8 !important;
|
| 736 |
}
|
| 737 |
</style>
|
| 738 |
+
/* استایل برای اسلایدر استاندارد Streamlit */
|
| 739 |
+
.stSlider {
|
| 740 |
+
direction: ltr !important; /* جلوگیری از بهمریختگی در rtl */
|
| 741 |
+
width: 100% !important;
|
| 742 |
+
margin: 0 auto !important;
|
| 743 |
+
padding: 0 !important;
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
.stSlider [role="slider"] {
|
| 747 |
+
background-color: #f0e6ff !important; /* رنگ پسزمینه مسیر */
|
| 748 |
+
height: 10px !important;
|
| 749 |
+
border-radius: 5px !important;
|
| 750 |
+
width: 100% !important;
|
| 751 |
+
position: relative !important;
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
.stSlider [role="slider"]::-webkit-slider-thumb {
|
| 755 |
+
background-color: #6a0dad !important; /* رنگ دستگیره */
|
| 756 |
+
border: 2px solid #ffffff !important;
|
| 757 |
+
width: 20px !important;
|
| 758 |
+
height: 20px !important;
|
| 759 |
+
border-radius: 50% !important;
|
| 760 |
+
cursor: pointer !important;
|
| 761 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
|
| 762 |
+
position: relative !important;
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
.stSlider [role="slider"]::-moz-range-thumb {
|
| 766 |
+
background-color: #6a0dad !important;
|
| 767 |
+
border: 2px solid #ffffff !important;
|
| 768 |
+
width: 20px !important;
|
| 769 |
+
height: 20px !important;
|
| 770 |
+
border-radius: 50% !important;
|
| 771 |
+
cursor: pointer !important;
|
| 772 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
|
| 773 |
+
position: relative !important;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
.stSlider [role="slider"]::-webkit-slider-runnable-track {
|
| 777 |
+
background-color: #f0e6ff !important;
|
| 778 |
+
height: 10px !important;
|
| 779 |
+
border-radius: 5px !important;
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
.stSlider [role="slider"]::-moz-range-track {
|
| 783 |
+
background-color: #f0e6ff !important;
|
| 784 |
+
height: 10px !important;
|
| 785 |
+
border-radius: 5px !important;
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
/* استایل برای لیبلهای اسلایدر */
|
| 789 |
+
.slider-labels {
|
| 790 |
+
display: flex !important;
|
| 791 |
+
justify-content: space-between !important;
|
| 792 |
+
font-size: 12px !important;
|
| 793 |
+
margin-bottom: 5px !important;
|
| 794 |
+
color: #333333 !important;
|
| 795 |
+
font-family: 'B Nazanin' !important;
|
| 796 |
+
direction: rtl !important;
|
| 797 |
+
width: 100% !important;
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
/* استایل برای متن پاسخ انتخابشده */
|
| 801 |
+
.slider-response {
|
| 802 |
+
text-align: center !important;
|
| 803 |
+
color: #6a0dad !important;
|
| 804 |
+
font-weight: bold !important;
|
| 805 |
+
margin-top: 10px !important;
|
| 806 |
+
font-family: 'B Nazanin' !important;
|
| 807 |
+
direction: rtl !important;
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
/* جلوگیری از پریدن اسلایدر */
|
| 811 |
+
.stSlider > div {
|
| 812 |
+
width: 100% !important;
|
| 813 |
+
padding: 0 !important;
|
| 814 |
+
margin: 0 !important;
|
| 815 |
+
direction: ltr !important;
|
| 816 |
+
}
|
| 817 |
""", unsafe_allow_html=True)
|
| 818 |
|
| 819 |
# ========== توابع اصلی ==========
|
| 820 |
def custom_likert_slider(question_data):
|
| 821 |
+
"""نمایش سوال لیکرت با اسلایدر استاندارد Streamlit"""
|
| 822 |
question = question_data["question"]
|
| 823 |
key = question_data["key"]
|
| 824 |
points = question_data["scale"]
|
| 825 |
labels = question_data.get("labels", ["کمترین", "بیشترین"]) # لیبلهای پیشفرض
|
| 826 |
+
|
| 827 |
# مقدار پیشفرض (وسط طیف)
|
| 828 |
default_value = (points + 1) // 2
|
| 829 |
+
|
| 830 |
+
# نمایش سوال
|
| 831 |
+
st.markdown(f"<p style='font-size:16px; margin-bottom:5px;'>{question}</p>", unsafe_allow_html=True)
|
| 832 |
+
|
| 833 |
+
# لیبلهای دو طرف
|
| 834 |
+
st.markdown(
|
| 835 |
+
f"""
|
| 836 |
+
<div class="slider-labels">
|
|
|
|
| 837 |
<span>{labels[0]}</span>
|
| 838 |
<span>{labels[1]}</span>
|
| 839 |
</div>
|
| 840 |
+
""",
|
| 841 |
+
unsafe_allow_html=True
|
| 842 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 843 |
|
| 844 |
+
# اسلایدر استاندارد Streamlit
|
| 845 |
+
value = st.slider(
|
| 846 |
+
"",
|
| 847 |
+
min_value=1,
|
| 848 |
+
max_value=points,
|
| 849 |
+
value=st.session_state.get(key, default_value),
|
| 850 |
+
step=1,
|
| 851 |
+
key=key,
|
| 852 |
+
format="%d"
|
| 853 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 854 |
|
| 855 |
+
# نمایش پاسخ انتخابشده
|
| 856 |
+
st.markdown(
|
| 857 |
+
f"""
|
| 858 |
+
<p class="slider-response">
|
| 859 |
+
پاسخ انتخابشده: {value}
|
| 860 |
+
</p>
|
| 861 |
+
""",
|
| 862 |
+
unsafe_allow_html=True
|
| 863 |
+
)
|
| 864 |
+
|
| 865 |
+
# دیباگ
|
| 866 |
+
st.write(f"Debug: مقدار ذخیرهشده برای {key}: {value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
# ذخیره مقدار
|
| 869 |
+
st.session_state[key] = value
|
| 870 |
+
return value
|
|
|
|
| 871 |
|
| 872 |
def create_ride_map():
|
| 873 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|