# app.py - COMPLETE FIXED VERSION import streamlit as st import os # ============================================ # SESSION FIX # ============================================ # Check if we have OAuth code in URL but no session try: query_params = st.query_params if hasattr(st, 'query_params') else st.experimental_get_query_params() if "code" in query_params and "authenticated" not in st.session_state: # We need to process OAuth callback st.switch_page("pages/oauth_callback.py") except: pass # ============================================ # MAIN DASHBOARD # ============================================ def show_dashboard(): """Show the main dashboard after login""" # Verify session if "user_info" not in st.session_state: st.error("Session expired. Please login again.") st.session_state.clear() st.rerun() return user = st.session_state.user_info # Apply your original styling st.markdown(""" """, unsafe_allow_html=True) # Header with user info st.markdown(f"""

🔍 Social Media Data Extractor

Welcome back, {user.get('name', 'User')}! 👋

""", unsafe_allow_html=True) # Sidebar with user info and logout - FIXED with st.sidebar: if user.get('picture'): st.image(user.get('picture'), width=80) else: st.image("https://cdn-icons-png.flaticon.com/512/149/149071.png", width=80) st.write(f"**👤 {user.get('name', 'User')}**") st.write(f"📧 {user.get('email', '')}") st.markdown("---") # LOGOUT BUTTON - This should show now if st.button("🚪 Logout", use_container_width=True, type="primary"): st.session_state.clear() st.rerun() # Platform selection st.markdown("## 🚀 Launch Extractors") col1, col2, col3 = st.columns(3) with col1: st.markdown("""

💼 LinkedIn Extractor

""", unsafe_allow_html=True) if st.button("🚀 Launch LinkedIn Extractor", key="linkedin_btn", use_container_width=True): st.switch_page("pages/linkedin_extractor.py") with col2: st.markdown("""

📘 Facebook Extractor

""", unsafe_allow_html=True) if st.button("🚀 Launch Facebook Extractor", key="facebook_btn", use_container_width=True): st.switch_page("pages/facebook_extractor.py") with col3: st.markdown("""

🔥 Facebook Extractor 2.0

""", unsafe_allow_html=True) if st.button("🚀 Launch Facebook Extractor 2.0", key="facebook_pro_btn", use_container_width=True): st.switch_page("pages/facebook_extractor_pro.py") # Instructions with st.expander("📋 How to Use", expanded=True): st.markdown(f""" 1. **Click any extractor to launch** 2. **For LinkedIn:** Enter any LinkedIn URL 3. **For Facebook:** Public data extraction available 4. **AI Analysis:** Chat with extracted data **Note:** All extractors are 100% free and require no local setup. **Logged in as:** {user.get('email', 'User')} """) # ============================================ # LOGIN PAGE # ============================================ def show_login_page(): """Show login page if user is not authenticated""" GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "") if not GOOGLE_CLIENT_ID: st.error("Google OAuth not configured") return st.title("🔐 Social Media Data Extractor") st.markdown("### Welcome! Please login to continue") # Create login URL redirect_uri = "https://refat81-social-media-data-extractor-chatbot.hf.space/oauth_callback" 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" st.markdown(f"""
Sign in with Google
""", unsafe_allow_html=True) # ============================================ # MAIN APP # ============================================ def main(): """Main app routing""" st.set_page_config( page_title="Social Media Data Extractor", page_icon="🔍", layout="wide", initial_sidebar_state="expanded" ) # DEBUG: Remove this after fixing if "user_info" in st.session_state: st.sidebar.success(f"Logged in as: {st.session_state.user_info.get('name')}") # Check authentication if "authenticated" in st.session_state and st.session_state.authenticated: show_dashboard() else: show_login_page() if __name__ == "__main__": main()