jaothan commited on
Commit
36080eb
·
verified ·
1 Parent(s): 64702f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -5
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import streamlit as st
 
 
 
2
 
3
  # Page config
4
  st.set_page_config(page_title="AI Maturity Model", layout="wide")
@@ -12,7 +15,20 @@ sections = [
12
  "Finance, Tax & Legal",
13
  "Data & Technology"
14
  ]
15
- selected_section = st.sidebar.radio("Select Section", sections)
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Sample questions per section
18
  questions_dict = {
@@ -64,14 +80,49 @@ st.title(f"{selected_section}")
64
 
65
  questions = questions_dict.get(selected_section, [])
66
 
 
 
67
  for idx, q in enumerate(questions):
68
- st.subheader(f"Q{idx + 1}: {q['question']}")
69
- st.radio("", q["options"], key=f"q{idx}")
70
  st.markdown("---")
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  # Navigation Buttons
73
  col1, col2 = st.columns([1, 1])
74
  with col1:
75
- st.button("Previous Section")
 
76
  with col2:
77
- st.button("Next Section")
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import smtplib
4
+ from email.mime.text import MIMEText
5
 
6
  # Page config
7
  st.set_page_config(page_title="AI Maturity Model", layout="wide")
 
15
  "Finance, Tax & Legal",
16
  "Data & Technology"
17
  ]
18
+
19
+ # Session state for navigation
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 = {
 
80
 
81
  questions = questions_dict.get(selected_section, [])
82
 
83
+ responses = []
84
+
85
  for idx, q in enumerate(questions):
86
+ response = st.radio(f"Q{idx + 1}: {q['question']}", q["options"], key=f"q{idx}")
87
+ responses.append({"Section": selected_section, "Question": q["question"], "Answer": response})
88
  st.markdown("---")
89
 
90
+ # Convert responses to DataFrame
91
+ df = pd.DataFrame(responses)
92
+
93
+ # Email function
94
+ def send_email(dataframe):
95
+ sender_email = "your_email@example.com"
96
+ sender_password = "your_password"
97
+ recipient_email = "recipient@example.com"
98
+ subject = "AI Maturity Model Responses"
99
+ body = dataframe.to_string(index=False)
100
+
101
+ msg = MIMEText(body)
102
+ msg['Subject'] = subject
103
+ msg['From'] = sender_email
104
+ msg['To'] = recipient_email
105
+
106
+ try:
107
+ with smtplib.SMTP("smtp.example.com", 587) as server:
108
+ server.starttls()
109
+ server.login(sender_email, sender_password)
110
+ server.sendmail(sender_email, recipient_email, msg.as_string())
111
+ st.success("Responses submitted successfully!")
112
+ except Exception as e:
113
+ st.error(f"Error sending responses: {e}")
114
+
115
+ # Submit button
116
+ if st.button("Submit Questionnaire"):
117
+ send_email(df)
118
+
119
  # Navigation Buttons
120
  col1, col2 = st.columns([1, 1])
121
  with col1:
122
+ if st.button("Previous Section"):
123
+ prev_section()
124
  with col2:
125
+ if st.button("Next Section"):
126
+ next_section()
127
+
128
+ st.experimental_rerun()