GSMEthesis commited on
Commit
1ee8fea
·
verified ·
1 Parent(s): 49d58ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -43
app.py CHANGED
@@ -1546,66 +1546,84 @@ def explanation_questions():
1546
  key=f"explanation_q_{current_q['key']}"
1547
  )
1548
 
1549
- # اگر سوال مربوط به explanation_received باشد، دکمه مثال را نمایش بده
1550
- if current_q["key"] == "explanation_received":
1551
- # مدیریت حالت باز/بسته بودن مدال
1552
- if "show_modal" not in st.session_state:
1553
- st.session_state.show_modal = False
1554
 
 
 
1555
  if st.button("مشاهده مثال از توضیحات", key="show_example_btn"):
1556
  st.session_state.show_modal = True
1557
 
1558
- # نمایش مدال اگر باز باشد
1559
- from PIL import Image
1560
-
1561
- # نمایش تصاویر در یک مدال
1562
- if st.session_state.show_modal:
1563
- with st.container():
1564
- st.markdown("""
1565
  <style>
1566
- .modal {
1567
  position: fixed;
1568
  top: 0;
1569
  left: 0;
1570
- width: 100%;
1571
- height: 100%;
1572
- background-color: rgba(0,0,0,0.8);
1573
  z-index: 1000;
1574
  display: flex;
1575
- flex-direction: column;
1576
- align-items: center;
1577
  justify-content: center;
 
1578
  }
1579
- .modal-content {
1580
  background: white;
1581
- padding: 20px;
1582
  border-radius: 10px;
1583
- max-width: 80%;
1584
- max-height: 80%;
1585
- overflow: auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1586
  }
1587
  </style>
1588
- <div class="modal">
1589
- <div class="modal-content">
1590
- """, unsafe_allow_html=True)
1591
-
1592
- try:
1593
- img1 = Image.open("explanation_control.png")
1594
- st.image(img1, caption="مثال توضیحات")
1595
-
1596
- img2 = Image.open("explanation_input.png")
1597
- st.image(img2, caption="مثال ورودی")
1598
-
1599
- img3 = Image.open("explanation_counterfactual.png")
1600
- st.image(img3, caption="مثال شرایط متفاوت")
1601
- except FileNotFoundError:
1602
- st.error("فایل تصویر یافت نشد!")
1603
-
1604
- st.markdown("</div></div>", unsafe_allow_html=True)
1605
-
1606
- if st.button("بستن"):
 
 
 
 
1607
  st.session_state.show_modal = False
1608
- st.rerun()
1609
 
1610
  # دکمه ادامه
1611
  if st.button("ادامه", key=f"continue_{current_q['key']}"):
@@ -1620,6 +1638,12 @@ def explanation_questions():
1620
 
1621
  # رفرش صفحه برای نمایش سوال بعدی
1622
  st.rerun()
 
 
 
 
 
 
1623
 
1624
  def demographic_form():
1625
  """فرم اطلاعات دموگرافیک"""
 
1546
  key=f"explanation_q_{current_q['key']}"
1547
  )
1548
 
 
 
 
 
 
1549
 
1550
+ # وقتی به سوال explanation_received رسیدیم
1551
+ if current_q["key"] == "explanation_received":
1552
  if st.button("مشاهده مثال از توضیحات", key="show_example_btn"):
1553
  st.session_state.show_modal = True
1554
 
1555
+ # نمایش مدال
1556
+ if st.session_state.show_modal:
1557
+ # استایل‌های ریسپانسیو
1558
+ modal_style = """
 
 
 
1559
  <style>
1560
+ .modal-overlay {
1561
  position: fixed;
1562
  top: 0;
1563
  left: 0;
1564
+ right: 0;
1565
+ bottom: 0;
1566
+ background-color: rgba(0,0,0,0.7);
1567
  z-index: 1000;
1568
  display: flex;
 
 
1569
  justify-content: center;
1570
+ align-items: center;
1571
  }
1572
+ .modal-container {
1573
  background: white;
 
1574
  border-radius: 10px;
1575
+ width: 90%;
1576
+ max-width: 500px;
1577
+ max-height: 90vh;
1578
+ overflow-y: auto;
1579
+ padding: 20px;
1580
+ position: relative;
1581
+ }
1582
+ .close-btn {
1583
+ position: absolute;
1584
+ top: 10px;
1585
+ left: 10px;
1586
+ font-size: 24px;
1587
+ cursor: pointer;
1588
+ color: #333;
1589
+ }
1590
+ .modal-image {
1591
+ width: 100%;
1592
+ margin: 10px 0;
1593
+ border-radius: 5px;
1594
+ }
1595
+ @media (max-width: 600px) {
1596
+ .modal-container {
1597
+ width: 95%;
1598
+ padding: 15px;
1599
+ }
1600
  }
1601
  </style>
1602
+ """
1603
+
1604
+ # محتوای مدال
1605
+ modal_content = f"""
1606
+ {modal_style}
1607
+ <div class="modal-overlay">
1608
+ <div class="modal-container">
1609
+ <div class="close-btn" onclick="document.getElementById('close-modal').click()">×</div>
1610
+ <h3 style="text-align: center; margin-bottom: 20px;">نمونه توضیحات قیمت‌گذاری</h3>
1611
+
1612
+ <img class="modal-image" src="data:image/png;base64,{img_to_base64('explanation_control.png')}">
1613
+ <img class="modal-image" src="data:image/png;base64,{img_to_base64('explanation_input.png')}">
1614
+ <img class="modal-image" src="data:image/png;base64,{img_to_base64('explanation_counterfactual.png')}">
1615
+ </div>
1616
+ </div>
1617
+ <button id="close-modal" style="display: none;"></button>
1618
+ """
1619
+
1620
+ # نمایش مدال
1621
+ st.components.v1.html(modal_content, height=0)
1622
+
1623
+ # دکمه بستن در استریملیت
1624
+ if st.button("بستن", key="modal_close_btn"):
1625
  st.session_state.show_modal = False
1626
+ st.rerun()
1627
 
1628
  # دکمه ادامه
1629
  if st.button("ادامه", key=f"continue_{current_q['key']}"):
 
1638
 
1639
  # رفرش صفحه برای نمایش سوال بعدی
1640
  st.rerun()
1641
+
1642
+ # تابع کمکی برای تبدیل تصویر به base64
1643
+ def img_to_base64(img_path):
1644
+ import base64
1645
+ with open(img_path, "rb") as img_file:
1646
+ return base64.b64encode(img_file.read()).decode('utf-8')
1647
 
1648
  def demographic_form():
1649
  """فرم اطلاعات دموگرافیک"""