GSMEthesis commited on
Commit
ac5a01c
·
verified ·
1 Parent(s): 922eea0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -38
app.py CHANGED
@@ -738,52 +738,34 @@ h3 {
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 - نسخه اصلاح شده با مناطق عمومی"""
 
738
  """, unsafe_allow_html=True)
739
 
740
  # ========== توابع اصلی ==========
741
+
742
  def custom_likert_slider(question_data):
743
+ """Custom Likert Slider function for Streamlit"""
744
  question = question_data["question"]
745
  key = question_data["key"]
746
  points = question_data["scale"]
747
+ labels = question_data.get("labels", ["کمترین", "بیشترین"]) # Default labels
748
 
749
+ # Default value (middle of the scale)
750
  default_value = st.session_state.get(key, (points + 1) // 2)
751
 
752
+ # HTML and JavaScript for the slider
753
+ slider_value = st.slider(
754
+ label=question,
755
+ min_value=1,
756
+ max_value=points,
757
+ value=default_value,
758
+ step=1,
759
+ format="%d"
760
+ )
 
 
 
 
 
 
761
 
762
+ # Update the session state to save the value
763
+ st.session_state[key] = slider_value
764
+
765
+ # Display the value selected by the user
766
+ st.markdown(f"**انتخاب شده**: {slider_value} ({labels[0]} - {labels[1]})")
767
+
768
+ return slider_value
 
 
 
 
 
 
 
 
 
 
 
 
 
769
 
770
  def create_ride_map():
771
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""