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| 1 |
+
import streamlit as st
|
| 2 |
+
from st_paywall import add_auth
|
| 3 |
+
from st_paywall.google_auth import get_logged_in_user_email, show_login_button
|
| 4 |
+
from st_paywall.stripe_auth import is_active_subscriber, redirect_button
|
| 5 |
+
from st_paywall.buymeacoffee_auth import get_bmac_payers
|
| 6 |
+
import st_paywall.google_auth as google_auth
|
| 7 |
+
import st_paywall.stripe_auth as stripe_auth
|
| 8 |
+
|
| 9 |
+
payment_provider = st.secrets.get("payment_provider", "stripe")
|
| 10 |
+
|
| 11 |
+
def add_auth(
|
| 12 |
+
required: bool = True,
|
| 13 |
+
login_button_text: str = "Login with Google",
|
| 14 |
+
login_button_color: str = "#FD504D",
|
| 15 |
+
login_sidebar: bool = True,
|
| 16 |
+
subscribe_color_button = "#FFA500",
|
| 17 |
+
|
| 18 |
+
):
|
| 19 |
+
if required:
|
| 20 |
+
require_auth(
|
| 21 |
+
login_button_text=login_button_text,
|
| 22 |
+
login_sidebar=login_sidebar,
|
| 23 |
+
login_button_color=login_button_color,
|
| 24 |
+
)
|
| 25 |
+
else:
|
| 26 |
+
optional_auth(
|
| 27 |
+
login_button_text=login_button_text,
|
| 28 |
+
login_sidebar=login_sidebar,
|
| 29 |
+
login_button_color=login_button_color,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def require_auth(
|
| 35 |
+
login_button_text: str = "Login with Google",
|
| 36 |
+
login_button_color: str = "#FD504D",
|
| 37 |
+
subscribe_button_color: str = "#FFA500",
|
| 38 |
+
login_sidebar: bool = True,):
|
| 39 |
+
|
| 40 |
+
user_email = get_logged_in_user_email()
|
| 41 |
+
|
| 42 |
+
if not user_email:
|
| 43 |
+
show_login_button(
|
| 44 |
+
text=login_button_text, color=login_button_color, sidebar=login_sidebar
|
| 45 |
+
)
|
| 46 |
+
st.stop()
|
| 47 |
+
if payment_provider == "stripe":
|
| 48 |
+
is_subscriber = user_email and is_active_subscriber(user_email)
|
| 49 |
+
elif payment_provider == "bmac":
|
| 50 |
+
is_subscriber = user_email and user_email in get_bmac_payers()
|
| 51 |
+
else:
|
| 52 |
+
raise ValueError("payment_provider must be 'stripe' or 'bmac'")
|
| 53 |
+
|
| 54 |
+
if not is_subscriber:
|
| 55 |
+
redirect_button(
|
| 56 |
+
text="Subscribe now!",
|
| 57 |
+
customer_email=user_email,
|
| 58 |
+
payment_provider=payment_provider,
|
| 59 |
+
)
|
| 60 |
+
st.session_state.user_subscribed = False
|
| 61 |
+
st.stop()
|
| 62 |
+
elif is_subscriber:
|
| 63 |
+
st.session_state.user_subscribed = True
|
| 64 |
+
|
| 65 |
+
if st.sidebar.button("Logout", type="primary"):
|
| 66 |
+
del st.session_state.email
|
| 67 |
+
del st.session_state.user_subscribed
|
| 68 |
+
st.rerun()
|
| 69 |
+
|
| 70 |
+
def optional_auth(
|
| 71 |
+
login_button_text: str = "Login with Google",
|
| 72 |
+
login_button_color: str = "#FD504D",
|
| 73 |
+
login_sidebar: bool = True,
|
| 74 |
+
subscribe_button_color: str = "#FFA500", # Add this line
|
| 75 |
+
):
|
| 76 |
+
user_email = get_logged_in_user_email()
|
| 77 |
+
if payment_provider == "stripe":
|
| 78 |
+
is_subscriber = user_email and is_active_subscriber(user_email)
|
| 79 |
+
elif payment_provider == "bmac":
|
| 80 |
+
is_subscriber = user_email and user_email in get_bmac_payers()
|
| 81 |
+
else:
|
| 82 |
+
raise ValueError("payment_provider must be 'stripe' or 'bmac'")
|
| 83 |
+
|
| 84 |
+
if not user_email:
|
| 85 |
+
show_login_button(
|
| 86 |
+
text=login_button_text, color=login_button_color, sidebar=login_sidebar
|
| 87 |
+
)
|
| 88 |
+
st.session_state.email = ""
|
| 89 |
+
st.sidebar.markdown("")
|
| 90 |
+
|
| 91 |
+
if not is_subscriber:
|
| 92 |
+
redirect_button(
|
| 93 |
+
text="Subscribe now!", customer_email="", payment_provider=payment_provider, color=subscribe_button_color
|
| 94 |
+
)
|
| 95 |
+
st.sidebar.markdown("")
|
| 96 |
+
st.session_state.user_subscribed = False
|
| 97 |
+
|
| 98 |
+
elif is_subscriber:
|
| 99 |
+
st.session_state.user_subscribed = True
|
| 100 |
+
|
| 101 |
+
if st.session_state.email != "":
|
| 102 |
+
if st.sidebar.button("Logout", type="primary"):
|
| 103 |
+
del st.session_state.email
|
| 104 |
+
del st.session_state.user_subscribed
|
| 105 |
+
st.rerun()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
st.set_page_config(
|
| 110 |
+
page_title="UAP Analytics",
|
| 111 |
+
page_icon="🛸",
|
| 112 |
+
layout="wide",
|
| 113 |
+
initial_sidebar_state="expanded",
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
add_auth(required=False, login_button_color="#FFA500",subscribe_color_button="#FFA500")
|
| 117 |
+
|
| 118 |
+
if st.session_state.email is not '':
|
| 119 |
+
st.write(f'User: {st.session_state.email}')
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
if "buttons" in st.session_state:
|
| 123 |
+
st.session_state.buttons = st.session_state.buttons
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
from PIL import Image
|
| 128 |
+
import base64
|
| 129 |
+
|
| 130 |
+
def get_base64_of_bin_file(bin_file):
|
| 131 |
+
with open(bin_file, 'rb') as f:
|
| 132 |
+
data = f.read()
|
| 133 |
+
return base64.b64encode(data).decode()
|
| 134 |
+
|
| 135 |
+
def set_png_as_page_bg(png_file):
|
| 136 |
+
bin_str = get_base64_of_bin_file(png_file)
|
| 137 |
+
page_bg_img = '''
|
| 138 |
+
<style>
|
| 139 |
+
.stApp {
|
| 140 |
+
background-image: url("data:image/png;base64,%s");
|
| 141 |
+
background-size: cover;
|
| 142 |
+
}
|
| 143 |
+
</style>
|
| 144 |
+
''' % bin_str
|
| 145 |
+
st.markdown(page_bg_img, unsafe_allow_html=True)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
if st.toggle('Set background image', True):
|
| 149 |
+
set_png_as_page_bg('saucer.webp') # Replace with your background image path
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
pg = st.navigation([
|
| 153 |
+
st.Page("rag_search.py", title="Smart-Search (Retrieval Augmented Generations)", icon="🔍"),
|
| 154 |
+
st.Page("parsing.py", title="UAP Feature Extraction (Shape, Speed, Color)", icon="📄"),
|
| 155 |
+
st.Page("analyzing.py", title="Statistical Analysis (UMAP+HDBSCAN, XGBoost, V-Cramer)", icon="🧠"),
|
| 156 |
+
st.Page("magnetic.py", title="Magnetic Anomaly Detection (InterMagnet Stations)", icon="����"),
|
| 157 |
+
st.Page("map.py", title="Interactive Map (Tracking variations, Proximity with Military Bases, Nuclear Facilities)", icon="🗺️"),
|
| 158 |
+
])
|
| 159 |
+
|
| 160 |
+
pg.run()
|