Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -734,118 +734,57 @@ h3 {
|
|
| 734 |
margin-bottom: 1em !important;
|
| 735 |
line-height: 1.8 !important;
|
| 736 |
}
|
| 737 |
-
/* استایل برای اسلایدر استاندارد Streamlit */
|
| 738 |
-
.stSlider [role="slider"] {
|
| 739 |
-
background-color: #f0e6ff !important; /* رنگ پسزمینه مسیر */
|
| 740 |
-
height: 10px !important;
|
| 741 |
-
border-radius: 5px !important;
|
| 742 |
-
}
|
| 743 |
-
|
| 744 |
-
.stSlider [role="slider"]::-webkit-slider-thumb {
|
| 745 |
-
background-color: #6a0dad !important; /* رنگ دستگیره */
|
| 746 |
-
border: 2px solid #ffffff !important;
|
| 747 |
-
width: 20px !important;
|
| 748 |
-
height: 20px !important;
|
| 749 |
-
border-radius: 50% !important;
|
| 750 |
-
cursor: pointer !important;
|
| 751 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
|
| 752 |
-
}
|
| 753 |
-
|
| 754 |
-
.stSlider [role="slider"]::-moz-range-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 |
-
}
|
| 763 |
-
|
| 764 |
-
.stSlider [role="slider"]::-webkit-slider-runnable-track {
|
| 765 |
-
background-color: #f0e6ff !important;
|
| 766 |
-
height: 10px !important;
|
| 767 |
-
border-radius: 5px !important;
|
| 768 |
-
}
|
| 769 |
-
|
| 770 |
-
.stSlider [role="slider"]::-moz-range-track {
|
| 771 |
-
background-color: #f0e6ff !important;
|
| 772 |
-
height: 10px !important;
|
| 773 |
-
border-radius: 5px !important;
|
| 774 |
-
}
|
| 775 |
-
|
| 776 |
-
/* استایل برای لیبلهای اسلایدر */
|
| 777 |
-
.slider-labels {
|
| 778 |
-
display: flex !important;
|
| 779 |
-
justify-content: space-between !important;
|
| 780 |
-
font-size: 12px !important;
|
| 781 |
-
margin-bottom: 5px !important;
|
| 782 |
-
color: #333333 !important;
|
| 783 |
-
font-family: 'B Nazanin' !important;
|
| 784 |
-
}
|
| 785 |
-
|
| 786 |
-
/* استایل برای متن پاسخ انتخابشده */
|
| 787 |
-
.slider-response {
|
| 788 |
-
text-align: center !important;
|
| 789 |
-
color: #6a0dad !important;
|
| 790 |
-
font-weight: bold !important;
|
| 791 |
-
margin-top: 10px !important;
|
| 792 |
-
font-family: 'B Nazanin' !important;
|
| 793 |
-
}
|
| 794 |
</style>
|
| 795 |
""", unsafe_allow_html=True)
|
| 796 |
|
| 797 |
# ========== توابع اصلی ==========
|
| 798 |
def custom_likert_slider(question_data):
|
| 799 |
-
"""نمایش سوال لیکرت با اسلایدر
|
| 800 |
question = question_data["question"]
|
| 801 |
key = question_data["key"]
|
| 802 |
points = question_data["scale"]
|
| 803 |
labels = question_data.get("labels", ["کمترین", "بیشترین"]) # لیبلهای پیشفرض
|
| 804 |
-
|
| 805 |
# مقدار پیشفرض (وسط طیف)
|
| 806 |
-
default_value = (points + 1) // 2
|
| 807 |
-
|
| 808 |
-
#
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
f"""
|
| 814 |
-
<div class="slider-labels">
|
| 815 |
<span>{labels[0]}</span>
|
| 816 |
<span>{labels[1]}</span>
|
| 817 |
</div>
|
| 818 |
-
"""
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
min_value=1,
|
| 826 |
-
max_value=points,
|
| 827 |
-
value=st.session_state.get(key, default_value),
|
| 828 |
-
step=1,
|
| 829 |
-
key=key,
|
| 830 |
-
format="%d"
|
| 831 |
-
)
|
| 832 |
-
|
| 833 |
-
# نمایش پاسخ انتخابشده
|
| 834 |
-
st.markdown(
|
| 835 |
-
f"""
|
| 836 |
-
<p class="slider-response">
|
| 837 |
-
پاسخ انتخابشده: {value}
|
| 838 |
-
</p>
|
| 839 |
-
""",
|
| 840 |
-
unsafe_allow_html=True
|
| 841 |
-
)
|
| 842 |
|
| 843 |
-
|
| 844 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
|
| 846 |
-
# ذخی��ه مقدار
|
| 847 |
-
st.session_state[key] = value
|
| 848 |
-
return value
|
| 849 |
def create_ride_map():
|
| 850 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
| 851 |
# نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
|
|
|
|
| 734 |
margin-bottom: 1em !important;
|
| 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 = st.session_state.get(key, (points + 1) // 2)
|
| 750 |
+
|
| 751 |
+
# HTML و JavaScript
|
| 752 |
+
html = f"""
|
| 753 |
+
<div id="container_{key}" style="direction: ltr; font-family: 'B Nazanin'; margin-bottom: 30px;">
|
| 754 |
+
<label style="font-size: 16px; font-weight: bold; display: block; text-align: right;">{question}</label>
|
| 755 |
+
<div style="display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px;">
|
|
|
|
|
|
|
| 756 |
<span>{labels[0]}</span>
|
| 757 |
<span>{labels[1]}</span>
|
| 758 |
</div>
|
| 759 |
+
<input type="range" id="{key}" min="1" max="{points}" step="1" value="{default_value}"
|
| 760 |
+
style="width: 100%; height: 10px; accent-color: #6a0dad; margin-bottom: 15px;"
|
| 761 |
+
oninput="updateSlider('{key}')">
|
| 762 |
+
<div style="text-align: center; margin-top: 10px; direction: rtl;">
|
| 763 |
+
پاسخ انتخابشده: <strong><span id="output_{key}">{default_value}</span></strong>
|
| 764 |
+
</div>
|
| 765 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
|
| 767 |
+
<script>
|
| 768 |
+
function updateSlider(key) {{
|
| 769 |
+
const value = parseInt(document.getElementById(key).value);
|
| 770 |
+
document.getElementById('output_' + key).innerText = value;
|
| 771 |
+
|
| 772 |
+
// ارسال مقدار به Streamlit
|
| 773 |
+
window.parent.postMessage({{
|
| 774 |
+
type: 'streamlit:setComponentValue',
|
| 775 |
+
key: key,
|
| 776 |
+
value: value
|
| 777 |
+
}}, '*');
|
| 778 |
+
}}
|
| 779 |
+
</script>
|
| 780 |
+
"""
|
| 781 |
+
|
| 782 |
+
# نمایش کامپوننت
|
| 783 |
+
components.html(html, height=150)
|
| 784 |
+
|
| 785 |
+
# مقدار نهایی
|
| 786 |
+
return st.session_state.get(key, default_value)
|
| 787 |
|
|
|
|
|
|
|
|
|
|
| 788 |
def create_ride_map():
|
| 789 |
"""ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
|
| 790 |
# نقاط تقریبی برای مناطق عمومی جنوب و غرب تهران
|