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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -72
app.py CHANGED
@@ -771,7 +771,10 @@ body, .stApp {
771
  """, unsafe_allow_html=True)
772
 
773
  # ========== توابع اصلی ==========
 
 
774
  def enhanced_likert_scale(question_data):
 
775
  question = question_data["question"]
776
  key = question_data["key"]
777
  scale = question_data["scale"]
@@ -782,41 +785,21 @@ def enhanced_likert_scale(question_data):
782
  st.session_state[key] = 0
783
 
784
  # نمایش سوال
785
- st.markdown(f"<div style='text-align:center; font-weight:bold; margin-bottom:15px;'>{question}</div>",
786
- unsafe_allow_html=True)
 
 
787
 
788
- # تابع کمکی برای ساخت HTML پویا
789
- def build_scale_html(current_value):
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: Ascending;
820
  margin: 5px auto 15px;
821
  display: flex;
822
  justify-content: space-between;
@@ -825,63 +808,52 @@ def enhanced_likert_scale(question_data):
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 {{ width: 90%; }}
837
- .likert-labels {{ width: 90%; }}
838
- }}
839
  </style>
840
- <div>
841
- <div class="likert-labels">
842
- <span>{labels[1]}</span>
843
- <span>{labels[0]}</span>
844
- </div>
845
- <div class="likert-line">
846
- """
847
- for i in range(1, scale + 1):
848
- value = scale - i + 1
849
- active_class = "active" if current_value == value else ""
850
- scale_html += f"<div class='likert-dot {active_class}'></div>"
851
- scale_html += "</div></div>"
852
- return scale_html
853
-
854
- # رندر HTML با مقدار فعلی
855
- components.html(build_scale_html(st.session_state[key]), height=60)
856
-
857
- # ورودی عددی
858
- value = st.number_input(
859
- "پاسخ شما (از 1 تا 7):",
860
  min_value=0,
861
  max_value=scale,
862
  value=st.session_state[key],
863
  step=1,
864
- key=f"{key}_input",
865
- placeholder="0 (پاسخ نداده) یا 1-7",
866
- format="%d"
867
  )
868
 
869
- # به‌روزرسانی مقدار در session_state
870
  if value != st.session_state[key]:
871
  st.session_state[key] = value
872
 
 
 
 
 
 
 
873
  # خط جداکننده
874
- st.markdown("""
875
- <style>
876
- .likert-separator {
877
- width: 80%;
878
- height: 2px;
879
- background: #6a0dad;
880
- margin: 20px auto;
881
- }
882
- </style>
883
- <div class="likert-separator"></div>
884
- """, unsafe_allow_html=True)
885
 
886
  return st.session_state[key]
887
 
 
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"]
 
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;
 
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