Spaces:
Running
Running
Update contact.py
Browse files- contact.py +56 -55
contact.py
CHANGED
@@ -1,55 +1,56 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
|
4 |
+
# Load EmailJS credentials securely from secrets.toml
|
5 |
+
public_key = st.secrets["emailjs"]["public_key"]
|
6 |
+
service_id = st.secrets["emailjs"]["service_id"]
|
7 |
+
template_id = st.secrets["emailjs"]["template_id"]
|
8 |
+
|
9 |
+
st.title("π¬ Contact Us")
|
10 |
+
st.write("Feel free to reach out to us by filling the form below.")
|
11 |
+
|
12 |
+
# Contact form using Streamlit
|
13 |
+
with st.form(key="contact_form"):
|
14 |
+
name = st.text_input("Your Name")
|
15 |
+
email = st.text_input("Your Email")
|
16 |
+
message = st.text_area("Your Message")
|
17 |
+
submit_button = st.form_submit_button("Send")
|
18 |
+
|
19 |
+
if submit_button:
|
20 |
+
if name and email and message:
|
21 |
+
st.success("Sending your message...")
|
22 |
+
|
23 |
+
js_code = f"""
|
24 |
+
var templateParams = {{
|
25 |
+
name: "{name}",
|
26 |
+
email: "{email}",
|
27 |
+
message: `{message}`
|
28 |
+
}};
|
29 |
+
|
30 |
+
emailjs.send("{service_id}", "{template_id}", templateParams, "{public_key}")
|
31 |
+
.then(function(response) {{
|
32 |
+
console.log("SUCCESS!", response.status, response.text);
|
33 |
+
window.parent.postMessage({{"type": "success", "message": "Email sent successfully!"}}, "*");
|
34 |
+
}}, function(error) {{
|
35 |
+
console.log("FAILED...", error);
|
36 |
+
window.parent.postMessage({{"type": "error", "message": "Failed to send email."}}, "*");
|
37 |
+
}});
|
38 |
+
"""
|
39 |
+
|
40 |
+
components.html(f"""
|
41 |
+
<html>
|
42 |
+
<head>
|
43 |
+
<script src="https://cdn.jsdelivr.net/npm/emailjs-com@2.6.4/dist/email.min.js"></script>
|
44 |
+
<script>
|
45 |
+
(function() {{
|
46 |
+
emailjs.init("{public_key}");
|
47 |
+
{js_code}
|
48 |
+
}})();
|
49 |
+
</script>
|
50 |
+
</head>
|
51 |
+
<body></body>
|
52 |
+
</html>
|
53 |
+
""", height=0)
|
54 |
+
|
55 |
+
else:
|
56 |
+
st.error("Please fill out all the fields.")
|