GSMEthesis commited on
Commit
9764203
·
verified ·
1 Parent(s): 71e74b9

Update app.py

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