Spaces:
Paused

GSMEthesis commited on
Commit
6f4e7db
·
verified ·
1 Parent(s): 696863c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -805,28 +805,20 @@ def enhanced_likert_scale(question_data):
805
  </div>
806
  """, unsafe_allow_html=True)
807
 
808
- # ایجاد دکمه‌ها از راست به چپ (7 تا 1)
809
  btn_cols = st.columns(scale)
810
  for i in range(scale):
811
- with btn_cols[i]:
812
  value = scale - i # مقدار از 7 به 1
813
- is_selected = st.session_state.get(key) == value
814
- btn_style = (
815
- "background-color: #6a0dad; color: white;"
816
- if is_selected
817
- else "background-color: white; color: #6a0dad;"
818
- )
819
- st.markdown(
820
- f"<div style='{btn_style} border: 2px solid #6a0dad; border-radius: 50%; "
821
- f"width: 40px; height: 40px; display: flex; align-items: center; "
822
- f"justify-content: center; cursor: pointer; margin: 0 auto;' "
823
- f"onclick='window.parent.postMessage({{type: \"streamlit:setComponentValue\", "
824
- f"key: \"{key}\", value: {value}}}, \"*\")'>{value}</div>",
825
- unsafe_allow_html=True
826
- )
827
 
828
- # نمایش پاسخ انتخاب شده
829
- if st.session_state.get(key) is not None:
830
  st.markdown(
831
  f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:10px;'>"
832
  f"پاسخ شما: {st.session_state[key]}"
 
805
  </div>
806
  """, unsafe_allow_html=True)
807
 
 
808
  btn_cols = st.columns(scale)
809
  for i in range(scale):
810
+ with btn_cols[i]: # مهم: اینجا i تغییر نکرده
811
  value = scale - i # مقدار از 7 به 1
812
+ if st.button(
813
+ str(value),
814
+ key=f"{key}_btn_{value}",
815
+ on_click=lambda v=value: st.session_state.update({key: v})
816
+ ):
817
+ st.session_state[key] = value
818
+ st.rerun()
 
 
 
 
 
 
 
819
 
820
+ # نمایش پاسخ (فقط اگر انتخاب شده باشد)
821
+ if st.session_state.get(key):
822
  st.markdown(
823
  f"<div style='text-align:center; color:#6a0dad; font-weight:bold; margin-top:10px;'>"
824
  f"پاسخ شما: {st.session_state[key]}"