GSMEthesis commited on
Commit
ca01ca7
·
verified ·
1 Parent(s): 0cfa4f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -64
app.py CHANGED
@@ -771,91 +771,126 @@ body, .stApp {
771
  """, unsafe_allow_html=True)
772
 
773
  # ========== توابع اصلی ==========
774
- import streamlit as st
775
-
776
  def enhanced_likert_scale(question_data):
777
- """لیکرت اسکیل ساده و بهینه با Streamlit slider"""
778
  question = question_data["question"]
779
  key = question_data["key"]
780
  scale = question_data["scale"]
781
  labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
782
-
783
  # مقداردهی اولیه
784
  if key not in st.session_state:
785
  st.session_state[key] = 0
786
 
787
  # نمایش سوال
788
- st.markdown(
789
- f"<div style='text-align:center; font-weight:bold; margin-bottom:15px;'>{question}</div>",
790
- unsafe_allow_html=True,
791
- )
792
-
793
- # استایل برای لیبل‌ها و خط
794
- st.markdown(
795
- """
796
- <style>
797
- @font-face {
798
- font-family: 'Vazir';
799
- src: url('https://cdn.fontcdn.ir/Font/Persian/Vazir/Vazir-Bold.woff2') format('woff2');
800
- }
801
- .likert-labels {
802
- width: 80%;
803
- margin: 5px auto 15px;
804
- display: flex;
805
- justify-content: space-between;
806
- direction: rtl;
807
- font-size: 14px;
808
- font-family: 'Vazir', sans-serif;
809
- font-weight: bold;
810
- color: #6a0dad;
811
- }
812
- .likert-separator {
813
- width: 80%;
814
- height: 2px;
815
- background: #6a0dad;
816
- margin: 20px auto;
817
- }
818
- </style>
819
- """,
820
- unsafe_allow_html=True,
821
- )
822
-
823
- # نمایش لیبل‌ها
824
- st.markdown(
825
- f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826
  <div class="likert-labels">
827
- <span>{labels[1]}</span>
828
  <span>{labels[0]}</span>
 
829
  </div>
830
- """,
831
- unsafe_allow_html=True,
832
- )
 
 
 
 
 
 
 
 
 
 
 
833
 
834
- # استفاده از slider به جای number_input و HTML
835
- value = st.slider(
836
- "",
837
- min_value=0,
838
  max_value=scale,
839
- value=st.session_state[key],
840
  step=1,
841
- key=f "slider_{key}",
 
842
  format="%d",
 
843
  )
844
 
845
- # به‌روزرسانی session_state
846
- if value != st.session_state[key]:
847
- st.session_state[key] = value
848
-
849
- # نمایش مقدار انتخاب‌شده (اختیاری)
850
- st.markdown(
851
- f"<div style='text-align:center; font-size:14px; color:#6a0dad;'>پاسخ شما: {value}</div>",
852
- unsafe_allow_html=True,
853
- )
 
 
 
 
854
 
855
- # خط جداکننده
856
- st.markdown('<div class="likert-separator"></div>', unsafe_allow_html=True)
857
 
858
- return st.session_state[key]
859
 
860
  def create_ride_map():
861
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""
 
771
  """, unsafe_allow_html=True)
772
 
773
  # ========== توابع اصلی ==========
 
 
774
  def enhanced_likert_scale(question_data):
775
+ """لیکرت اسکیل با محدوده 0 تا scale و عدم نمایش نقطه برای 0"""
776
  question = question_data["question"]
777
  key = question_data["key"]
778
  scale = question_data["scale"]
779
  labels = question_data.get("labels", ["کاملاً مخالفم", "کاملاً موافقم"])
780
+
781
  # مقداردهی اولیه
782
  if key not in st.session_state:
783
  st.session_state[key] = 0
784
 
785
  # نمایش سوال
786
+ st.markdown(f"<div style='text-align:center; font-weight:bold; margin-bottom:15px;'>{question}</div>",
787
+ unsafe_allow_html=True)
788
+
789
+ # ایجاد خط و نقاط با HTML/CSS
790
+ scale_html = f"""
791
+ <style>
792
+ @font-face {{
793
+ font-family: 'Vazir';
794
+ src: url('https://cdn.fontcdn.ir/Font/Persian/Vazir/Vazir-Bold.woff2') format('woff2');
795
+ }}
796
+ .likert-line {{
797
+ width: 80%;
798
+ height: 2px;
799
+ background: #6a0dad;
800
+ margin: 0 auto;
801
+ position: relative;
802
+ display: flex;
803
+ justify-content: space-between;
804
+ direction: rtl;
805
+ }}
806
+ .likert-dot {{
807
+ width: 18px;
808
+ height: 18px;
809
+ border-radius: 50%;
810
+ background: white;
811
+ border: 2px solid #6a0dad;
812
+ position: relative;
813
+ top: -9px;
814
+ }}
815
+ .likert-dot.active {{
816
+ background: #6a0dad;
817
+ }}
818
+ .likert-labels {{
819
+ width: 80%;
820
+ margin: 5px auto 15px;
821
+ display: flex;
822
+ justify-content: space-between;
823
+ direction: rtl;
824
+ font-size: 14px;
825
+ font-family: 'Vazir', sans-serif;
826
+ font-weight: bold;
827
+ color: #6a0dad;
828
+ }}
829
+ .separator-line {{
830
+ width: 80%;
831
+ height: 2px;
832
+ background: #6a0dad;
833
+ margin: 20px auto;
834
+ }}
835
+ @media (max-width: 768px) {{
836
+ .likert-line {{
837
+ width: 90%;
838
+ }}
839
+ .likert-labels {{
840
+ width: 90%;
841
+ }}
842
+ }}
843
+ </style>
844
+
845
+ <div>
846
  <div class="likert-labels">
 
847
  <span>{labels[0]}</span>
848
+ <span>{labels[1]}</span>
849
  </div>
850
+ <div class="likert-line">
851
+ """
852
+
853
+ # اضافه کردن نقاط فقط برای مقادیر 1 تا scale
854
+ current_value = st.session_state.get(key, 0)
855
+ for i in range(1, scale+1):
856
+ value = i+1 # مقادیر از 1 تا scale
857
+ active_class = "active" if current_value == value else ""
858
+ scale_html += f"<div class='likert-dot {active_class}'></div>"
859
+
860
+ scale_html += "</div></div>"
861
+
862
+ # نمایش کامپوننت HTML
863
+ components.html(scale_html, height=60)
864
 
865
+ # ورودی عددی با محدوده 0 تا scale (0 قابل انتخاب است)
866
+ value = st.number_input(
867
+ "پاسخ شما (از 1 تا 7):",
868
+ min_value=0, # 0 مجاز است
869
  max_value=scale,
870
+ value=st.session_state.get(key, 0),
871
  step=1,
872
+ key=f"{key}_input",
873
+ placeholder="0 (پاسخ نداده) یا 1-7",
874
  format="%d",
875
+ on_change=lambda: st.session_state.update({key: st.session_state[f"{key}_input"]})
876
  )
877
 
878
+ # خط جداکننده بنفش
879
+ # خط جداکننده بنفش - تعریف استایل و HTML با هم
880
+ st.markdown("""
881
+ <style>
882
+ .likert-separator {
883
+ width: 80%;
884
+ height: 2px;
885
+ background: #6a0dad;
886
+ margin: 20px auto;
887
+ }
888
+ </style>
889
+ <div class="likert-separator"></div>
890
+ """, unsafe_allow_html=True)
891
 
892
+ return st.session_state.get(key)
 
893
 
 
894
 
895
  def create_ride_map():
896
  """ایجاد نقشه سفر با Folium - نسخه اصلاح شده با مناطق عمومی"""