Maryam Ilka commited on
Commit
d8fd72f
·
verified ·
1 Parent(s): 378a94f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -64
app.py CHANGED
@@ -123,29 +123,73 @@ st.markdown("""
123
  margin: 0 auto;
124
  width: 80%;
125
  max-width: 300px;
126
- height: 50px; /* ارتفاع ثابت */
127
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
128
- text-align: center; /* برای مرکز کردن متن */
129
  }
 
130
  .rahyar-button:hover {
131
  background-color: #7b1fa2 !important;
132
  transform: translateY(-2px);
133
  box-shadow: 0 6px 12px rgba(0,0,0,0.15);
134
  }
 
135
  .rahyar-button:active {
136
  transform: scale(0.98) translateY(0);
137
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
138
  }
139
- /* تنظیمات مخصوص دسکتاپ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  @media only screen and (min-width: 769px) {
141
  .folium-map {
142
- height: 400px !important; /* ارتفاع ثابت برای دسکتاپ */
143
  }
144
  :root {
145
- color-scheme: only light !important; # غیرفعال کردن تم تاریک
146
  }
147
  body {
148
- background-color: white !important; # پس‌زمینه سفید اجباری
149
  }
150
  .stApp {
151
  background-color: white !important;
@@ -248,7 +292,8 @@ def save_to_sheet(data):
248
  *data.get("transparency_answers", []),
249
  *data.get("fairness_answers", []),
250
  st.session_state.get("explanation_data", {}).get("explanation_received", ""),
251
- st.session_state.get("explanation_data", {}).get("explanation_type", "")
 
252
  ]
253
 
254
  worksheet.append_row(row_data)
@@ -297,7 +342,7 @@ def user_contact():
297
  key="user_contact_input"
298
  )
299
 
300
- if st.button("ادامه", key="continue_btn", type="primary"): # تغییر کلید
301
  st.session_state.user_contact = contact_info
302
  st.session_state.current_page = "demographic"
303
  st.rerun()
@@ -360,7 +405,7 @@ def scenario_explanation():
360
  st.rerun()
361
 
362
  def map_view():
363
- """نمایش نقشه و قیمت"""
364
  col1, col2 = st.columns([1, 4])
365
  with col1:
366
  try:
@@ -373,62 +418,51 @@ def map_view():
373
  <p style="color: #6a0dad; margin: 0;">همراه سفرهای درون‌شهری شما، راهی مطمئن، راهی روشن، رهیار</p>
374
  """, unsafe_allow_html=True)
375
 
376
- st.markdown("### مسیر سفر شما")
377
- folium_static(create_ride_map(), width=800, height=400)
378
-
379
- st.markdown(f"""
380
- <div class="price-container">
381
- <div style="display: flex; justify-content: space-between; align-items: center;">
382
- <span>راهیار <span class="rahyar-badge">به صرفه</span></span>
383
- <span class="rahyar-price">{st.session_state.price:,} تومان</span>
 
 
 
 
 
384
  </div>
385
- </div>
386
- """, unsafe_allow_html=True)
387
-
388
- show_explanation(st.session_state.scenario_type)
389
-
 
 
 
 
 
 
 
 
 
 
 
 
390
 
 
391
  st.markdown("""
392
- <div style="text-align: center; margin: 30px 0;">
393
- <button class="rahyar-button">
394
- <span style="display: inline-block; vertical-align: middle;">درخواست راهیار</span>
395
- </button>
396
- </div>
397
- """, unsafe_allow_html=True)
398
-
399
- if st.button("ادامه", key="request_btn", type="primary"):
400
- st.session_state.current_page = "transparency_questions"
401
- st.rerun()
402
-
403
- def create_likert_question(question, key):
404
- """سوال لیکرت با دکمه‌ها"""
405
- st.markdown(f"<p style='margin-bottom: 10px;'>{question}</p>", unsafe_allow_html=True)
406
-
407
- cols = st.columns(5)
408
- options = {
409
- 1: "کاملاً مخالفم",
410
- 2: "مخالفم",
411
- 3: "نظری ندارم",
412
- 4: "موافقم",
413
- 5: "کاملاً موافقم"
414
  }
415
-
416
- selected = st.session_state.get(key, None)
417
-
418
- for value, label in options.items():
419
- with cols[value-1]:
420
- if st.button(
421
- label,
422
- key=f"{key}_{value}",
423
- on_click=lambda v=value: st.session_state.update({key: v}),
424
- type="primary" if selected == value else "secondary"
425
- ):
426
- pass
427
-
428
- if selected:
429
- st.markdown(f"<p style='color: #6a0dad;'>پاسخ شما: {options[selected]}</p>", unsafe_allow_html=True)
430
-
431
- return selected
432
 
433
  def transparency_questions():
434
  """سوالات شفافیت"""
@@ -478,8 +512,6 @@ def fairness_questions():
478
  if st.button("ادامه به سوالات بعدی", type="primary"):
479
  st.session_state.current_page = "explanation_questions"
480
  st.rerun()
481
-
482
-
483
 
484
  def explanation_questions():
485
  """سوالات درباره توضیحات قیمت"""
@@ -540,7 +572,8 @@ def explanation_questions():
540
  "transparency_answers": st.session_state.transparency_answers,
541
  "fairness_answers": st.session_state.fairness_answers,
542
  "explanation_received": explanation_received,
543
- "explanation_type": explanation_type if explanation_received == "بله" else "N/A"
 
544
  }
545
 
546
  # ذخیره در Google Sheets
@@ -570,6 +603,7 @@ def main():
570
  st.session_state.transparency_answers = []
571
  st.session_state.fairness_answers = []
572
  st.session_state.explanation_data = None
 
573
 
574
  # نمایش صفحه فعلی
575
  pages = {
 
123
  margin: 0 auto;
124
  width: 80%;
125
  max-width: 300px;
126
+ height: 50px;
127
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
128
+ text-align: center;
129
  }
130
+
131
  .rahyar-button:hover {
132
  background-color: #7b1fa2 !important;
133
  transform: translateY(-2px);
134
  box-shadow: 0 6px 12px rgba(0,0,0,0.15);
135
  }
136
+
137
  .rahyar-button:active {
138
  transform: scale(0.98) translateY(0);
139
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
140
  }
141
+
142
+ .app-container {
143
+ background-color: #f3e5ff;
144
+ border-radius: 20px;
145
+ padding: 20px;
146
+ margin: 20px auto;
147
+ max-width: 500px;
148
+ box-shadow: 0 4px 15px rgba(106, 13, 173, 0.2);
149
+ }
150
+
151
+ .reject-button {
152
+ background-color: white !important;
153
+ color: #6a0dad !important;
154
+ border: 2px solid #6a0dad !important;
155
+ padding: 14px 28px !important;
156
+ border-radius: 12px !important;
157
+ font-weight: bold !important;
158
+ font-size: 16px !important;
159
+ cursor: pointer;
160
+ transition: all 0.3s ease;
161
+ display: flex;
162
+ justify-content: center;
163
+ align-items: center;
164
+ margin: 10px auto;
165
+ width: 80%;
166
+ max-width: 300px;
167
+ height: 50px;
168
+ box-shadow: 0 4px 8px rgba(0,0,0,0.1);
169
+ text-align: center;
170
+ }
171
+
172
+ .reject-button:hover {
173
+ background-color: #f8f0ff !important;
174
+ transform: translateY(-2px);
175
+ box-shadow: 0 6px 12px rgba(0,0,0,0.15);
176
+ }
177
+
178
+ .reject-button:active {
179
+ transform: scale(0.98) translateY(0);
180
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
181
+ }
182
+
183
+ /* تنظیمات مخصوص دسکتاپ */
184
  @media only screen and (min-width: 769px) {
185
  .folium-map {
186
+ height: 400px !important;
187
  }
188
  :root {
189
+ color-scheme: only light !important;
190
  }
191
  body {
192
+ background-color: white !important;
193
  }
194
  .stApp {
195
  background-color: white !important;
 
292
  *data.get("transparency_answers", []),
293
  *data.get("fairness_answers", []),
294
  st.session_state.get("explanation_data", {}).get("explanation_received", ""),
295
+ st.session_state.get("explanation_data", {}).get("explanation_type", ""),
296
+ data.get("price_accepted", 0) # اضافه کردن وضعیت پذیرش قیمت
297
  ]
298
 
299
  worksheet.append_row(row_data)
 
342
  key="user_contact_input"
343
  )
344
 
345
+ if st.button("ادامه", key="continue_btn", type="primary"):
346
  st.session_state.user_contact = contact_info
347
  st.session_state.current_page = "demographic"
348
  st.rerun()
 
405
  st.rerun()
406
 
407
  def map_view():
408
+ """نمایش نقشه و قیمت در قالب اپلیکیشن"""
409
  col1, col2 = st.columns([1, 4])
410
  with col1:
411
  try:
 
418
  <p style="color: #6a0dad; margin: 0;">همراه سفرهای درون‌شهری شما، راهی مطمئن، راهی روشن، رهیار</p>
419
  """, unsafe_allow_html=True)
420
 
421
+ # کانتینر اصلی اپلیکیشن
422
+ with st.container():
423
+ st.markdown('<div class="app-container">', unsafe_allow_html=True)
424
+
425
+ st.markdown("### مسیر سفر شما")
426
+ folium_static(create_ride_map(), width=800, height=400)
427
+
428
+ st.markdown(f"""
429
+ <div class="price-container">
430
+ <div style="display: flex; justify-content: space-between; align-items: center;">
431
+ <span>راهیار <span class="rahyar-badge">به صرفه</span></span>
432
+ <span class="rahyar-price">{st.session_state.price:,} تومان</span>
433
+ </div>
434
  </div>
435
+ """, unsafe_allow_html=True)
436
+
437
+ show_explanation(st.session_state.scenario_type)
438
+
439
+ # دکمه‌های جدید
440
+ st.markdown("""
441
+ <div style="text-align: center; margin: 30px 0;">
442
+ <button class="rahyar-button" onclick="acceptPrice()">
443
+ <span style="display: inline-block; vertical-align: middle;">درخواست راهیار</span>
444
+ </button>
445
+ <button class="reject-button" onclick="rejectPrice()">
446
+ <span style="display: inline-block; vertical-align: middle;">رد قیمت</span>
447
+ </button>
448
+ </div>
449
+ """, unsafe_allow_html=True)
450
+
451
+ st.markdown('</div>', unsafe_allow_html=True)
452
 
453
+ # اسکریپت برای مدیریت کلیک دکمه‌ها
454
  st.markdown("""
455
+ <script>
456
+ function acceptPrice() {
457
+ window.streamlitSessionState.set({"price_accepted": 1});
458
+ window.streamlitSessionState.set({"current_page": "transparency_questions"});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  }
460
+ function rejectPrice() {
461
+ window.streamlitSessionState.set({"price_accepted": 0});
462
+ window.streamlitSessionState.set({"current_page": "transparency_questions"});
463
+ }
464
+ </script>
465
+ """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
466
 
467
  def transparency_questions():
468
  """سوالات شفافیت"""
 
512
  if st.button("ادامه به سوالات بعدی", type="primary"):
513
  st.session_state.current_page = "explanation_questions"
514
  st.rerun()
 
 
515
 
516
  def explanation_questions():
517
  """سوالات درباره توضیحات قیمت"""
 
572
  "transparency_answers": st.session_state.transparency_answers,
573
  "fairness_answers": st.session_state.fairness_answers,
574
  "explanation_received": explanation_received,
575
+ "explanation_type": explanation_type if explanation_received == "بله" else "N/A",
576
+ "price_accepted": st.session_state.get("price_accepted", 0) # وضعیت پذیرش قیمت
577
  }
578
 
579
  # ذخیره در Google Sheets
 
603
  st.session_state.transparency_answers = []
604
  st.session_state.fairness_answers = []
605
  st.session_state.explanation_data = None
606
+ st.session_state.price_accepted = 0 # مقدار پیش‌فرض عدم پذیرش قیمت
607
 
608
  # نمایش صفحه فعلی
609
  pages = {