Spaces:
Runtime error
Runtime error
import base64 | |
import os | |
from datetime import datetime | |
from pathlib import Path | |
import mailerlite as MailerLite | |
import streamlit as st | |
client = MailerLite.Client({ | |
'api_key': os.environ['mailerlitetoken'] | |
}) | |
NEWSLETTER_GROUP_ID = "74940965074240697" | |
def get_timestamp(): | |
return datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
def add_logo_to_sidebar(): | |
st.markdown( | |
f""" | |
<style> | |
[data-testid="stSidebarNav"] {{ | |
background-image: url(data:image/png;base64,{base64.b64encode(Path('logo.png').read_bytes()).decode()}); | |
background-repeat: no-repeat; | |
background-position: 20px 20px; | |
background-size: 300px; | |
padding-top: 100px | |
}} | |
</style> | |
""", | |
unsafe_allow_html=True, | |
) | |
def add_footer(): | |
st.markdown(""" | |
### π€ Interested in hiring us to build bespoke Legal AI solutions? | |
- π Check out our [website](https://simplexico.ai) | |
- π Book a call with [us](https://calendly.com/uwais-iqbal/discovery-call) | |
- βοΈ Send us an [email](mailto:[email protected]) | |
""") | |
def add_email_signup_form(): | |
st.markdown("### π Join our mailing list to keep up to date with all things simplexico!") | |
col1, col2 = st.columns(2) | |
with st.form(key='email-form'): | |
name = col1.text_input(label='Enter your name', placeholder='John Doe') | |
email = col2.text_input(label='Enter your email', placeholder='[email protected]') | |
submit_button = st.form_submit_button(label='Submit', type='primary', use_container_width=True) | |
if submit_button: | |
valid_name = True | |
valid_email = True | |
if name == "": | |
st.error('β Error! Please enter a name.') | |
valid_name = False | |
if email == "": | |
st.error('β Error! Please enter an email.') | |
valid_email = False | |
elif not '@' in email: | |
st.error('β Error! Please enter a valid email.') | |
valid_email = False | |
elif not '.' in email.split('@')[-1]: | |
st.error('β Error! Please enter a valid email.') | |
valid_email = False | |
if valid_name and valid_email: | |
response = client.subscribers.create(email, fields={'name': name}, | |
groups=[NEWSLETTER_GROUP_ID], | |
status='active', subscribed_at=get_timestamp()) | |
try: | |
if response['data']['status'] == 'active': | |
st.success(f'β π Hey {name}! Welcome to our mailing list.') | |
except Exception as e: | |
st.error(f"π Sorry {name}. Something went wrong. We weren't able to add you to our mailing list.") | |