GSMEthesis commited on
Commit
135d05f
·
verified ·
1 Parent(s): 51a6712

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -68
app.py CHANGED
@@ -1206,67 +1206,6 @@ def attention_check1():
1206
  else:
1207
  st.warning("لطفاً یک گزینه را انتخاب کنید")
1208
 
1209
- import streamlit as st
1210
-
1211
- def custom_likert_slider(question_data):
1212
- """نمایش سوال لیکرت با اسلایدر پیش‌فرض Streamlit و ویژگی‌های شخصی‌سازی شده"""
1213
- question = question_data["question"]
1214
- key = question_data["key"]
1215
- points = question_data["scale"] # تعداد نقاط اسلایدر (مثلاً 7 نقطه)
1216
- labels = question_data.get("labels", ["کمترین", "بیشترین"]) # لیبل‌های پیش‌فرض
1217
-
1218
- # بررسی اینکه مقدار قبلاً در session_state ذخیره شده یا نه
1219
- if key not in st.session_state:
1220
- # اگر مقدار ذخیره نشده باشد، مقدار پیش‌فرض وسط طیف انتخاب می‌شود
1221
- st.session_state[key] = (points + 1) // 2
1222
-
1223
- # استفاده از key منحصر به فرد برای هر اسلایدر
1224
- value = st.slider(
1225
- question,
1226
- min_value=1,
1227
- max_value=points,
1228
- value=st.session_state[key],
1229
- step=1,
1230
- key=f"slider_{key}" # استفاده از key منحصر به فرد برای اسلایدر
1231
- )
1232
-
1233
- # ذخیره‌سازی مقدار انتخابی در session_state
1234
- st.session_state[key] = value
1235
-
1236
- # نمایش مقدار انتخاب‌شده زیر اسلایدر
1237
- st.markdown(f"<p style='text-align:center; color:#6a0dad; font-weight:bold;'>پاسخ انتخاب‌شده: {value}</p>", unsafe_allow_html=True)
1238
-
1239
- # شخصی‌سازی استایل‌ها برای سر و ته اسلایدر و نمایش عدد
1240
- st.markdown(f"""
1241
- <style>
1242
- .stSlider .st-bf .st-bc {{
1243
- display: flex;
1244
- justify-content: space-between;
1245
- font-size: 12px;
1246
- }}
1247
- .stSlider .st-bf .st-bc span {{
1248
- color: #6a0dad;
1249
- }}
1250
- div[role='slider'] {{
1251
- background: #e0e0e0 !important;
1252
- height: 8px !important;
1253
- border-radius: 5px !important;
1254
- }}
1255
- .stSlider input {{
1256
- accent-color: #6a0dad !important;
1257
- }}
1258
- .stSlider .st-bf {{
1259
- margin-top: 10px;
1260
- }}
1261
- .stSlider .st-bf .st-bc span {{
1262
- font-size: 14px;
1263
- }}
1264
- </style>
1265
- """, unsafe_allow_html=True)
1266
-
1267
- return value
1268
-
1269
-
1270
  def random_likert_questions():
1271
  """نمایش سوالات لیکرت به ترتیب مشخص"""
1272
  question_groups = [
@@ -1501,11 +1440,7 @@ def main():
1501
  user_agent = st.query_params.get("user_agent", [""])[0]
1502
  st.session_state.is_desktop = "mobile" not in user_agent.lower()
1503
 
1504
-
1505
- if st.session_state.is_desktop:
1506
- # اطمینان از نمایش همان حالت موبایل برای همه دستگاه‌ها
1507
- st.session_state.is_desktop = False
1508
-
1509
  if 'answers' not in st.session_state:
1510
  st.session_state.answers = {}
1511
 
@@ -1518,6 +1453,7 @@ def main():
1518
  st.session_state.price_accepted = 0
1519
  st.session_state.attention_check1 = None
1520
 
 
1521
  pages = {
1522
  "welcome": welcome_page,
1523
  "scenario_explanation": scenario_explanation,
@@ -1525,11 +1461,12 @@ def main():
1525
  "attention_check1": attention_check1,
1526
  "random_likert_questions": random_likert_questions,
1527
  "explanation_questions": explanation_questions,
1528
- "demographic": demographic_form, # دموگرافیک قبل از کانتکت
1529
- "contact": user_contact, # کانتکت در انتها
1530
  "thank_you": thank_you_page
1531
  }
1532
 
 
1533
  pages[st.session_state.current_page]()
1534
 
1535
  if __name__ == "__main__":
 
1206
  else:
1207
  st.warning("لطفاً یک گزینه را انتخاب کنید")
1208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1209
  def random_likert_questions():
1210
  """نمایش سوالات لیکرت به ترتیب مشخص"""
1211
  question_groups = [
 
1440
  user_agent = st.query_params.get("user_agent", [""])[0]
1441
  st.session_state.is_desktop = "mobile" not in user_agent.lower()
1442
 
1443
+ # مقداردهی اولیه session_state
 
 
 
 
1444
  if 'answers' not in st.session_state:
1445
  st.session_state.answers = {}
1446
 
 
1453
  st.session_state.price_accepted = 0
1454
  st.session_state.attention_check1 = None
1455
 
1456
+ # تعریف صفحات
1457
  pages = {
1458
  "welcome": welcome_page,
1459
  "scenario_explanation": scenario_explanation,
 
1461
  "attention_check1": attention_check1,
1462
  "random_likert_questions": random_likert_questions,
1463
  "explanation_questions": explanation_questions,
1464
+ "demographic": demographic_form,
1465
+ "contact": user_contact,
1466
  "thank_you": thank_you_page
1467
  }
1468
 
1469
+ # نمایش صفحه جاری
1470
  pages[st.session_state.current_page]()
1471
 
1472
  if __name__ == "__main__":