userIdc2024 commited on
Commit
1893ba9
·
verified ·
1 Parent(s): 72c3fcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +127 -0
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import streamlit as st
2
  from dotenv import load_dotenv
3
 
@@ -35,6 +38,130 @@ with st.sidebar:
35
  logout()
36
  st.rerun()
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  section = st.radio(" ", ["Gen AI", "AI Library"], index=0, horizontal=True, key="main_section")
39
 
40
  # ---------------------------- Gen AI ---------------------------------
 
1
+ import base64
2
+ from pathlib import Path
3
+
4
  import streamlit as st
5
  from dotenv import load_dotenv
6
 
 
38
  logout()
39
  st.rerun()
40
 
41
+ st.markdown(
42
+ """
43
+ <style>
44
+ .private-mode-banner {
45
+ padding: 0.75rem 1rem;
46
+ margin-top: 0.5rem;
47
+ border-radius: 0.85rem;
48
+ background: linear-gradient(125deg, rgba(91, 33, 182, 0.85), rgba(132, 94, 247, 0.55));
49
+ border: 1px solid rgba(132, 94, 247, 0.35);
50
+ color: #fff;
51
+ font-weight: 500;
52
+ box-shadow: 0 10px 24px rgba(82, 46, 173, 0.28);
53
+ animation: privateBannerSlide 0.55s ease forwards, privateBannerFade 3.3s ease 1.75s forwards;
54
+ }
55
+
56
+ .private-mode-banner-content {
57
+ display: flex;
58
+ align-items: flex-start;
59
+ gap: 0.85rem;
60
+ }
61
+
62
+ .private-mode-banner-copy {
63
+ display: flex;
64
+ flex-direction: column;
65
+ gap: 0.15rem;
66
+ }
67
+
68
+ .private-mode-icon {
69
+ width: 64px;
70
+ min-width: 48px;
71
+ max-width: 20%;
72
+ filter: drop-shadow(0 6px 16px rgba(16, 13, 61, 0.45));
73
+ opacity: 0.95;
74
+ }
75
+
76
+ .private-mode-banner small {
77
+ display: block;
78
+ opacity: 0.85;
79
+ font-weight: 400;
80
+ margin-top: 0.25rem;
81
+ letter-spacing: 0.01em;
82
+ }
83
+
84
+ @media (max-width: 320px) {
85
+ .private-mode-icon {
86
+ display: none;
87
+ }
88
+ }
89
+
90
+ @keyframes privateBannerSlide {
91
+ 0% { transform: translateY(-12px); opacity: 0; }
92
+ 60% { transform: translateY(2px); opacity: 1; }
93
+ 100% { transform: translateY(0); opacity: 1; }
94
+ }
95
+
96
+ @keyframes privateBannerFade {
97
+ to { opacity: 0; }
98
+ }
99
+
100
+ @keyframes privateToggleGlow {
101
+ 0% { box-shadow: 0 0 0 rgba(132, 94, 247, 0.0); }
102
+ 40% { box-shadow: 0 0 24px rgba(132, 94, 247, 0.55); }
103
+ 100% { box-shadow: 0 0 0 rgba(132, 94, 247, 0.0); }
104
+ }
105
+ </style>
106
+ """,
107
+ unsafe_allow_html=True,
108
+ )
109
+
110
+ prev_private_mode = st.session_state.get("_private_mode_prev", st.session_state.get("private_mode_enabled", False))
111
+ banner_slot = st.empty()
112
+
113
+ private_mode_default = st.session_state.get("private_mode_enabled", False)
114
+ private_mode = st.toggle(
115
+ "Private mode",
116
+ value=private_mode_default,
117
+ key="private_mode_enabled",
118
+ help="Skip saving prompts, jobs, and generated media to shared libraries."
119
+ )
120
+ just_enabled_private_mode = private_mode and not prev_private_mode
121
+ just_disabled_private_mode = (not private_mode) and prev_private_mode
122
+
123
+ if just_enabled_private_mode:
124
+ st.markdown(
125
+ """
126
+ <style>
127
+ div[data-testid="stSidebar"] div[data-testid="stToggle"] label {
128
+ animation: privateToggleGlow 2.45s ease-out 0s 1;
129
+ border-radius: 0.5rem;
130
+ }
131
+ </style>
132
+ """,
133
+ unsafe_allow_html=True,
134
+ )
135
+ icon_data_url = ""
136
+ try:
137
+ icon_path = Path(__file__).resolve().parent / "assets" / "private-mode.png"
138
+ icon_data_url = "data:image/png;base64," + base64.b64encode(icon_path.read_bytes()).decode("utf-8")
139
+ except Exception:
140
+ icon_data_url = ""
141
+
142
+ icon_html = f'<img src="{icon_data_url}" alt="Private mode icon" class="private-mode-icon" />' if icon_data_url else ""
143
+ banner_slot.markdown(
144
+ f"""
145
+ <div class="private-mode-banner">
146
+ <div class="private-mode-banner-content">
147
+ {icon_html}
148
+ <div class="private-mode-banner-copy">
149
+ Private mode is live for this session.
150
+ <small>We'll keep new generations off shared storage until you disable it.</small>
151
+ </div>
152
+ </div>
153
+ </div>
154
+ """,
155
+ unsafe_allow_html=True,
156
+ )
157
+ elif just_disabled_private_mode:
158
+ banner_slot.empty()
159
+
160
+ st.session_state["_private_mode_prev"] = private_mode
161
+
162
+ if private_mode:
163
+ st.caption("Private mode keeps this session's generations ephemeral—nothing is stored in the AI Library or external storage.")
164
+
165
  section = st.radio(" ", ["Gen AI", "AI Library"], index=0, horizontal=True, key="main_section")
166
 
167
  # ---------------------------- Gen AI ---------------------------------