GSMEthesis commited on
Commit
017e669
·
verified ·
1 Parent(s): da88d32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -52
app.py CHANGED
@@ -1202,7 +1202,8 @@ def explanation_questions():
1202
  {
1203
  "key": "price_increase_radio",
1204
  "label": "آیا به نظر شما در این سفر افزایش قیمت نسبت به حالت طبیعی وجود داشته است؟",
1205
- "options": ["بله", "خیر", "مطمئن نیستم"]
 
1206
  },
1207
  {
1208
  "key": "pricing_method_radio",
@@ -1212,17 +1213,20 @@ def explanation_questions():
1212
  "به صورت خودکار توسط هوش مصنوعی و الگوریتم‌ها",
1213
  "ترکیبی از هر دو روش",
1214
  "نظری ندارم"
1215
- ]
 
1216
  },
1217
  {
1218
  "key": "trust_radio",
1219
- "label": "آیا شما به تصمیم گیری هایی که توسط هوش مصنوعی انجام می شود اعتماد دارید؟",
1220
- "options": ["بله", "خیر", "نظری ندارم"]
 
1221
  },
1222
  {
1223
  "key": "explanation_received_radio",
1224
  "label": "آیا برای قیمت پیشنهادی این سفر، توضیحی به شما ارائه شد؟",
1225
- "options": ["بله", "خیر"]
 
1226
  },
1227
  {
1228
  "key": "explanation_type_radio",
@@ -1232,65 +1236,49 @@ def explanation_questions():
1232
  "شامل سناریوهای جایگزین که می‌توانستند قیمت متفاوتی ایجاد کنند",
1233
  "توضیحی دریافت نکردم"
1234
  ],
 
1235
  "condition": lambda: st.session_state.get("explanation_received_radio") == "بله"
1236
  }
1237
  ]
1238
 
1239
- # مقدار اولیه مرحله
1240
  if "explanation_step" not in st.session_state:
1241
  st.session_state.explanation_step = 0
1242
 
1243
- current_step = st.session_state.explanation_step
1244
 
1245
- if current_step < len(questions):
1246
- q = questions[current_step]
1247
-
1248
- # اگر شرط خاصی داره (مثل سوال پنجم)، بررسیش کن
1249
- if "condition" in q and not q["condition"]():
1250
- st.session_state.explanation_step += 1
1251
  st.rerun()
1252
- return
1253
-
1254
- # نمایش سوال فعلی
1255
- st.radio(
1256
- q["label"],
1257
- q["options"],
1258
- index=None,
1259
- key=q["key"]
1260
- )
1261
 
1262
- if st.button("ادامه", key=f"continue_{current_step}"):
1263
- response = st.session_state.get(q["key"])
1264
- if response is None:
1265
- st.warning("لطفاً یک گزینه را انتخاب کنید")
1266
- else:
1267
- # 🟣 ذخیره پاسخ فعلی در session_state
1268
- key_mapping = {
1269
- "trust_radio": "trust",
1270
- "pricing_method_radio": "pricing_method",
1271
- "price_increase_radio": "price_increase",
1272
- "explanation_received_radio": "explanation_received",
1273
- "explanation_type_radio": "explanation_type"
1274
- }
1275
- logical_key = key_mapping.get(q["key"])
1276
- if logical_key:
1277
- st.session_state[logical_key] = response
1278
-
1279
- st.session_state.explanation_step += 1
1280
- st.rerun()
1281
-
1282
- else:
1283
- # مرحله آخر: ذخیره داده‌ها و رفتن به فرم دموگرافیک
1284
- st.session_state.trust = st.session_state.get("trust_radio")
1285
- st.session_state.pricing_method = st.session_state.get("pricing_method_radio")
1286
- st.session_state.price_increase = st.session_state.get("price_increase_radio")
1287
- st.session_state.explanation_received = st.session_state.get("explanation_received_radio")
1288
- st.session_state.explanation_type = (
1289
- st.session_state.get("explanation_type_radio") if st.session_state.explanation_received == "بله" else "N/A"
1290
- )
1291
 
1292
- st.session_state.current_page = "demographic"
 
 
1293
  st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1294
 
1295
  def demographic_form():
1296
  """فرم اطلاعات دموگرافیک"""
 
1202
  {
1203
  "key": "price_increase_radio",
1204
  "label": "آیا به نظر شما در این سفر افزایش قیمت نسبت به حالت طبیعی وجود داشته است؟",
1205
+ "options": ["بله", "خیر", "مطمئن نیستم"],
1206
+ "logical_key": "price_increase"
1207
  },
1208
  {
1209
  "key": "pricing_method_radio",
 
1213
  "به صورت خودکار توسط هوش مصنوعی و الگوریتم‌ها",
1214
  "ترکیبی از هر دو روش",
1215
  "نظری ندارم"
1216
+ ],
1217
+ "logical_key": "pricing_method"
1218
  },
1219
  {
1220
  "key": "trust_radio",
1221
+ "label": "آیا شما به تصمیم‌گیری‌هایی که توسط هوش مصنوعی انجام می‌شود اعتماد دارید؟",
1222
+ "options": ["بله", "خیر", "نظری ندارم"],
1223
+ "logical_key": "trust"
1224
  },
1225
  {
1226
  "key": "explanation_received_radio",
1227
  "label": "آیا برای قیمت پیشنهادی این سفر، توضیحی به شما ارائه شد؟",
1228
+ "options": ["بله", "خیر"],
1229
+ "logical_key": "explanation_received"
1230
  },
1231
  {
1232
  "key": "explanation_type_radio",
 
1236
  "شامل سناریوهای جایگزین که می‌توانستند قیمت متفاوتی ایجاد کنند",
1237
  "توضیحی دریافت نکردم"
1238
  ],
1239
+ "logical_key": "explanation_type",
1240
  "condition": lambda: st.session_state.get("explanation_received_radio") == "بله"
1241
  }
1242
  ]
1243
 
1244
+ # مرحله فعلی
1245
  if "explanation_step" not in st.session_state:
1246
  st.session_state.explanation_step = 0
1247
 
1248
+ step = st.session_state.explanation_step
1249
 
1250
+ # وقتی همه سوالات تمام شدند
1251
+ if step >= len(questions):
1252
+ if st.button("اتمام و ادامه"):
1253
+ st.session_state.current_page = "demographic"
 
 
1254
  st.rerun()
1255
+ return
 
 
 
 
 
 
 
 
1256
 
1257
+ current_q = questions[step]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1258
 
1259
+ # اگر شرط خاصی داره (مثل سوال پنجم)، بررسیش کن
1260
+ if "condition" in current_q and not current_q["condition"]():
1261
+ st.session_state.explanation_step += 1
1262
  st.rerun()
1263
+ return
1264
+
1265
+ # نمایش سوال
1266
+ response = st.radio(
1267
+ current_q["label"],
1268
+ current_q["options"],
1269
+ index=None,
1270
+ key=current_q["key"]
1271
+ )
1272
+
1273
+ if st.button("ادامه", key=f"continue_{step}"):
1274
+ if response is None:
1275
+ st.warning("لطفاً یک گزینه را انتخاب کنید")
1276
+ else:
1277
+ # ذخیره پاسخ فعلی
1278
+ logical_key = current_q["logical_key"]
1279
+ st.session_state[logical_key] = response
1280
+ st.session_state.explanation_step += 1
1281
+ st.rerun()
1282
 
1283
  def demographic_form():
1284
  """فرم اطلاعات دموگرافیک"""