Refat81 commited on
Commit
2dfd4f4
Β·
verified Β·
1 Parent(s): f9852cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -92
app.py CHANGED
@@ -1,26 +1,19 @@
1
- # app.py - COMPLETE WORKING VERSION
2
  import streamlit as st
3
  import os
4
 
5
  # ============================================
6
- # COMPATIBILITY FUNCTIONS
7
  # ============================================
8
 
9
- def get_query_params():
10
- """Get query params with backward compatibility"""
11
- try:
12
- # Try new method (Streamlit 1.28+)
13
- return st.query_params
14
- except AttributeError:
15
- # Fallback to old method
16
- return st.experimental_get_query_params()
17
-
18
- def clear_query_params():
19
- """Clear query params with backward compatibility"""
20
- try:
21
- st.query_params.clear()
22
- except AttributeError:
23
- st.experimental_set_query_params()
24
 
25
  # ============================================
26
  # MAIN DASHBOARD
@@ -28,6 +21,13 @@ def clear_query_params():
28
 
29
  def show_dashboard():
30
  """Show the main dashboard after login"""
 
 
 
 
 
 
 
31
  user = st.session_state.user_info
32
 
33
  # Apply your original styling
@@ -51,7 +51,7 @@ def show_dashboard():
51
  </div>
52
  """, unsafe_allow_html=True)
53
 
54
- # Sidebar with user info and logout
55
  with st.sidebar:
56
  if user.get('picture'):
57
  st.image(user.get('picture'), width=80)
@@ -62,7 +62,8 @@ def show_dashboard():
62
  st.write(f"πŸ“§ {user.get('email', '')}")
63
  st.markdown("---")
64
 
65
- if st.button("πŸšͺ Logout", use_container_width=True):
 
66
  st.session_state.clear()
67
  st.rerun()
68
 
@@ -144,89 +145,36 @@ def show_login_page():
144
  GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "")
145
 
146
  if not GOOGLE_CLIENT_ID:
147
- st.error("""
148
- ⚠️ **Google OAuth not configured!**
149
-
150
- Please add these secrets to HuggingFace Space Settings:
151
-
152
- 1. Go to: Settings β†’ Repository Secrets
153
- 2. Add: `GOOGLE_CLIENT_ID` (your Google Client ID)
154
- 3. Add: `GOOGLE_CLIENT_SECRET` (your Google Client Secret)
155
- 4. Restart the Space
156
- """)
157
  return
158
 
159
- # Apply styling for login page
160
- st.markdown("""
161
- <style>
162
- .login-container {
163
- max-width: 500px;
164
- margin: 0 auto;
165
- padding: 2rem;
166
- text-align: center;
167
- }
168
- .google-btn {
169
- background: linear-gradient(135deg, #4285F4, #34A853);
170
- color: white;
171
- padding: 15px 30px;
172
- border-radius: 8px;
173
- border: none;
174
- cursor: pointer;
175
- font-size: 18px;
176
- font-weight: 600;
177
- display: inline-flex;
178
- align-items: center;
179
- justify-content: center;
180
- gap: 12px;
181
- margin: 20px 0;
182
- text-decoration: none;
183
- transition: all 0.3s ease;
184
- }
185
- .google-btn:hover {
186
- transform: translateY(-2px);
187
- box-shadow: 0 6px 20px rgba(66, 133, 244, 0.4);
188
- }
189
- </style>
190
- """, unsafe_allow_html=True)
191
-
192
- # Login page content
193
- st.markdown("""
194
- <div class="login-container">
195
- <h1>πŸ” Social Media Data Extractor</h1>
196
- <p style="font-size: 1.2rem; opacity: 0.9;">Secure login required to access extraction tools</p>
197
- <hr style="margin: 2rem 0;">
198
- </div>
199
- """, unsafe_allow_html=True)
200
-
201
  st.markdown("### Welcome! Please login to continue")
202
 
203
  # Create login URL
204
  redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback"
205
  login_url = f"https://accounts.google.com/o/oauth2/v2/auth?client_id={GOOGLE_CLIENT_ID}&redirect_uri={redirect_uri}&response_type=code&scope=openid%20email%20profile&access_type=offline&prompt=consent"
206
 
207
- # Google login button
208
  st.markdown(f"""
209
- <div style="text-align: center;">
210
- <a href="{login_url}" class="google-btn">
211
- <img src="https://cdn-icons-png.flaticon.com/512/2991/2991148.png" width="24" height="24">
 
 
 
 
 
 
 
 
 
 
 
 
212
  Sign in with Google
213
- </a>
214
- </div>
215
  """, unsafe_allow_html=True)
216
-
217
- # Instructions
218
- st.markdown("---")
219
- with st.expander("ℹ️ About this login", expanded=False):
220
- st.markdown("""
221
- **Why login is required:**
222
- - Securely store your extracted data
223
- - Prevent unauthorized access
224
- - Personalize your experience
225
- - Track your usage history
226
-
227
- **Privacy:** We only access your email and profile picture.
228
- Your data is never shared with third parties.
229
- """)
230
 
231
  # ============================================
232
  # MAIN APP
@@ -241,7 +189,11 @@ def main():
241
  initial_sidebar_state="expanded"
242
  )
243
 
244
- # Check if user is logged in
 
 
 
 
245
  if "authenticated" in st.session_state and st.session_state.authenticated:
246
  show_dashboard()
247
  else:
 
1
+ # app.py - COMPLETE FIXED VERSION
2
  import streamlit as st
3
  import os
4
 
5
  # ============================================
6
+ # SESSION FIX
7
  # ============================================
8
 
9
+ # Check if we have OAuth code in URL but no session
10
+ try:
11
+ query_params = st.query_params if hasattr(st, 'query_params') else st.experimental_get_query_params()
12
+ if "code" in query_params and "authenticated" not in st.session_state:
13
+ # We need to process OAuth callback
14
+ st.switch_page("pages/oauth_callback.py")
15
+ except:
16
+ pass
 
 
 
 
 
 
 
17
 
18
  # ============================================
19
  # MAIN DASHBOARD
 
21
 
22
  def show_dashboard():
23
  """Show the main dashboard after login"""
24
+ # Verify session
25
+ if "user_info" not in st.session_state:
26
+ st.error("Session expired. Please login again.")
27
+ st.session_state.clear()
28
+ st.rerun()
29
+ return
30
+
31
  user = st.session_state.user_info
32
 
33
  # Apply your original styling
 
51
  </div>
52
  """, unsafe_allow_html=True)
53
 
54
+ # Sidebar with user info and logout - FIXED
55
  with st.sidebar:
56
  if user.get('picture'):
57
  st.image(user.get('picture'), width=80)
 
62
  st.write(f"πŸ“§ {user.get('email', '')}")
63
  st.markdown("---")
64
 
65
+ # LOGOUT BUTTON - This should show now
66
+ if st.button("πŸšͺ Logout", use_container_width=True, type="primary"):
67
  st.session_state.clear()
68
  st.rerun()
69
 
 
145
  GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "")
146
 
147
  if not GOOGLE_CLIENT_ID:
148
+ st.error("Google OAuth not configured")
 
 
 
 
 
 
 
 
 
149
  return
150
 
151
+ st.title("πŸ” Social Media Data Extractor")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  st.markdown("### Welcome! Please login to continue")
153
 
154
  # Create login URL
155
  redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback"
156
  login_url = f"https://accounts.google.com/o/oauth2/v2/auth?client_id={GOOGLE_CLIENT_ID}&redirect_uri={redirect_uri}&response_type=code&scope=openid%20email%20profile&access_type=offline&prompt=consent"
157
 
 
158
  st.markdown(f"""
159
+ <a href="{login_url}">
160
+ <div style="
161
+ background-color: #4285F4;
162
+ color: white;
163
+ padding: 15px 30px;
164
+ border-radius: 8px;
165
+ border: none;
166
+ cursor: pointer;
167
+ font-size: 18px;
168
+ font-weight: 600;
169
+ text-align: center;
170
+ margin: 30px 0;
171
+ display: inline-block;
172
+ ">
173
+ <img src="https://cdn-icons-png.flaticon.com/512/2991/2991148.png" width="24" height="24" style="vertical-align: middle; margin-right: 12px;">
174
  Sign in with Google
175
+ </div>
176
+ </a>
177
  """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  # ============================================
180
  # MAIN APP
 
189
  initial_sidebar_state="expanded"
190
  )
191
 
192
+ # DEBUG: Remove this after fixing
193
+ if "user_info" in st.session_state:
194
+ st.sidebar.success(f"Logged in as: {st.session_state.user_info.get('name')}")
195
+
196
+ # Check authentication
197
  if "authenticated" in st.session_state and st.session_state.authenticated:
198
  show_dashboard()
199
  else: