jaothan commited on
Commit
a20aa1b
·
verified ·
1 Parent(s): ce472b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -20,15 +20,21 @@ sections = [
20
  if "section_index" not in st.session_state:
21
  st.session_state.section_index = 0
22
 
 
 
 
 
 
 
23
  def next_section():
24
  if st.session_state.section_index < len(sections) - 1:
25
  st.session_state.section_index += 1
 
26
 
27
  def prev_section():
28
  if st.session_state.section_index > 0:
29
  st.session_state.section_index -= 1
30
-
31
- selected_section = sections[st.session_state.section_index]
32
 
33
  # Sample questions per section
34
  questions_dict = {
@@ -90,10 +96,32 @@ for idx, q in enumerate(questions):
90
  # Convert responses to DataFrame
91
  df = pd.DataFrame(responses)
92
 
93
-
94
- # Submit button
95
- if st.button("Submit Questionnaire"):
96
- send_email(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  # Navigation Buttons
99
  col1, col2 = st.columns([1, 1])
@@ -103,5 +131,3 @@ with col1:
103
  with col2:
104
  if st.button("Next Section"):
105
  next_section()
106
-
107
- st.rerun()
 
20
  if "section_index" not in st.session_state:
21
  st.session_state.section_index = 0
22
 
23
+ # Sidebar for navigation
24
+ with st.sidebar:
25
+ st.header("Navigation")
26
+ selected_section = st.radio("Select Section", sections, index=st.session_state.section_index, key="sidebar_nav")
27
+ st.session_state.section_index = sections.index(selected_section)
28
+
29
  def next_section():
30
  if st.session_state.section_index < len(sections) - 1:
31
  st.session_state.section_index += 1
32
+ st.rerun()
33
 
34
  def prev_section():
35
  if st.session_state.section_index > 0:
36
  st.session_state.section_index -= 1
37
+ st.rerun()
 
38
 
39
  # Sample questions per section
40
  questions_dict = {
 
96
  # Convert responses to DataFrame
97
  df = pd.DataFrame(responses)
98
 
99
+ # Email function
100
+ def send_email(dataframe):
101
+ sender_email = "your_email@example.com"
102
+ sender_password = "your_password"
103
+ recipient_email = "recipient@example.com"
104
+ subject = "AI Maturity Model Responses"
105
+ body = dataframe.to_string(index=False)
106
+
107
+ msg = MIMEText(body)
108
+ msg['Subject'] = subject
109
+ msg['From'] = sender_email
110
+ msg['To'] = recipient_email
111
+
112
+ try:
113
+ with smtplib.SMTP("smtp.example.com", 587) as server:
114
+ server.starttls()
115
+ server.login(sender_email, sender_password)
116
+ server.sendmail(sender_email, recipient_email, msg.as_string())
117
+ st.success("Responses submitted successfully!")
118
+ except Exception as e:
119
+ st.error(f"Error sending responses: {e}")
120
+
121
+ # Show submit button only on last section
122
+ if selected_section == "Data & Technology":
123
+ if st.button("Submit Questionnaire"):
124
+ send_email(df)
125
 
126
  # Navigation Buttons
127
  col1, col2 = st.columns([1, 1])
 
131
  with col2:
132
  if st.button("Next Section"):
133
  next_section()