Spaces:
Sleeping
Sleeping
import streamlit as st | |
from st_paywall import add_auth | |
from st_paywall.google_auth import get_logged_in_user_email, show_login_button | |
from st_paywall.stripe_auth import is_active_subscriber, redirect_button | |
from st_paywall.buymeacoffee_auth import get_bmac_payers | |
import st_paywall.google_auth as google_auth | |
import st_paywall.stripe_auth as stripe_auth | |
payment_provider = st.secrets.get("payment_provider", "stripe") | |
def add_auth( | |
required: bool = True, | |
login_button_text: str = "Login with Google", | |
login_button_color: str = "#FD504D", | |
login_sidebar: bool = True, | |
subscribe_color_button = "#FFA500", | |
): | |
if required: | |
require_auth( | |
login_button_text=login_button_text, | |
login_sidebar=login_sidebar, | |
login_button_color=login_button_color, | |
) | |
else: | |
optional_auth( | |
login_button_text=login_button_text, | |
login_sidebar=login_sidebar, | |
login_button_color=login_button_color, | |
) | |
def require_auth( | |
login_button_text: str = "Login with Google", | |
login_button_color: str = "#FD504D", | |
subscribe_button_color: str = "#FFA500", | |
login_sidebar: bool = True,): | |
user_email = get_logged_in_user_email() | |
if not user_email: | |
show_login_button( | |
text=login_button_text, color=login_button_color, sidebar=login_sidebar | |
) | |
st.stop() | |
if payment_provider == "stripe": | |
is_subscriber = user_email and is_active_subscriber(user_email) | |
elif payment_provider == "bmac": | |
is_subscriber = user_email and user_email in get_bmac_payers() | |
else: | |
raise ValueError("payment_provider must be 'stripe' or 'bmac'") | |
if not is_subscriber: | |
redirect_button( | |
text="Make a Donation", | |
customer_email=user_email, | |
payment_provider=payment_provider, | |
) | |
st.session_state.user_subscribed = False | |
st.stop() | |
elif is_subscriber: | |
st.session_state.user_subscribed = True | |
if st.sidebar.button("Logout", type="primary"): | |
del st.session_state.email | |
del st.session_state.user_subscribed | |
st.rerun() | |
def optional_auth( | |
login_button_text: str = "Login with Google", | |
login_button_color: str = "#FD504D", | |
login_sidebar: bool = True, | |
subscribe_button_color: str = "#FFA500", # Add this line | |
): | |
user_email = get_logged_in_user_email() | |
if payment_provider == "stripe": | |
is_subscriber = user_email and is_active_subscriber(user_email) | |
elif payment_provider == "bmac": | |
is_subscriber = user_email and user_email in get_bmac_payers() | |
else: | |
raise ValueError("payment_provider must be 'stripe' or 'bmac'") | |
if not user_email: | |
show_login_button( | |
text=login_button_text, color=login_button_color, sidebar=login_sidebar | |
) | |
st.session_state.email = "" | |
st.sidebar.markdown("") | |
if not is_subscriber: | |
redirect_button( | |
text="Subscribe now!", customer_email="", payment_provider=payment_provider, color=subscribe_button_color | |
) | |
st.sidebar.markdown("") | |
st.session_state.user_subscribed = False | |
elif is_subscriber: | |
st.session_state.user_subscribed = True | |
if st.session_state.email != "": | |
if st.sidebar.button("Logout", type="primary"): | |
del st.session_state.email | |
del st.session_state.user_subscribed | |
st.rerun() | |
st.set_page_config( | |
page_title="UAP Analytics", | |
page_icon="๐ธ", | |
layout="wide", | |
initial_sidebar_state="expanded", | |
) | |
add_auth(required=False, login_button_color="#FFA500",subscribe_color_button="#FFA500") | |
if st.session_state.email is not '': | |
st.write('') | |
st.write(f'User: {st.session_state.email}') | |
if "buttons" in st.session_state: | |
st.session_state.buttons = st.session_state.buttons | |
from PIL import Image | |
import base64 | |
def get_base64_of_bin_file(bin_file): | |
with open(bin_file, 'rb') as f: | |
data = f.read() | |
return base64.b64encode(data).decode() | |
def set_png_as_page_bg(png_file): | |
bin_str = get_base64_of_bin_file(png_file) | |
page_bg_img = ''' | |
<style> | |
.stApp { | |
background-image: url("data:image/png;base64,%s"); | |
background-size: cover; | |
} | |
</style> | |
''' % bin_str | |
st.markdown(page_bg_img, unsafe_allow_html=True) | |
if st.toggle('Set background image', True): | |
set_png_as_page_bg('saucer.webp') # Replace with your background image path | |
pg = st.navigation([ | |
st.Page("rag_search.py", title="Smart-Search (Retrieval Augmented Generations)", icon="๐"), | |
st.Page("parsing.py", title="UAP Feature Extraction (Shape, Speed, Color)", icon="๐"), | |
st.Page("analyzing.py", title="Statistical Analysis (UMAP+HDBSCAN, XGBoost, V-Cramer)", icon="๐ง "), | |
st.Page("magnetic.py", title="Magnetic Anomaly Detection (InterMagnet Stations)", icon="๐งฒ"), | |
st.Page("map.py", title="Interactive Map (Tracking variations, Proximity with Military Bases, Nuclear Facilities)", icon="๐บ๏ธ"), | |
]) | |
pg.run() | |