File size: 7,264 Bytes
2dfd4f4 b1d820a e88e50c 4a8bf99 99cdd6b 2dfd4f4 99cdd6b 2dfd4f4 99cdd6b 8ecd1b3 99cdd6b 2dfd4f4 8ecd1b3 99cdd6b 2dfd4f4 99cdd6b 2dfd4f4 99cdd6b 8ecd1b3 99cdd6b 8ecd1b3 4a8bf99 8ecd1b3 99cdd6b 8ecd1b3 99cdd6b 8ecd1b3 99cdd6b 8ecd1b3 99cdd6b 8ecd1b3 99cdd6b 8ecd1b3 99cdd6b 8ecd1b3 2dfd4f4 e88e50c b1d820a 2dfd4f4 99cdd6b 2dfd4f4 e88e50c 2dfd4f4 e88e50c 99cdd6b 2dfd4f4 99cdd6b 4a8bf99 b1d820a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# 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("""
<style>
.stApp { background-color: #0e1117; color: white; }
.main-header { background: linear-gradient(135deg, #1a2a6c, #b21f1f); color: white; padding: 2rem; border-radius: 10px; text-align: center; margin-bottom: 2rem; }
.platform-card { background-color: #262730; padding: 1.5rem; border-radius: 10px; border-left: 4px solid; margin: 1rem 0; height: 280px; }
.linkedin-card { border-left-color: #0077B5; }
.facebook-card { border-left-color: #1877F2; }
.facebook-pro-card { border-left-color: #FF6B35; }
.feature-list { margin: 1rem 0; padding-left: 1.5rem; flex-grow: 1; }
</style>
""", unsafe_allow_html=True)
# Header with user info
st.markdown(f"""
<div class="main-header">
<h1 style="margin:0;">π Social Media Data Extractor</h1>
<p style="margin:0; opacity: 0.9;">Welcome back, {user.get('name', 'User')}! π</p>
</div>
""", 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("""
<div class="platform-card linkedin-card">
<h3>πΌ LinkedIn Extractor</h3>
<ul class="feature-list">
<li>No login required</li>
<li>Profile, company, and post analysis</li>
<li>Quick data extraction</li>
<li>AI-powered insights</li>
<li>100% Free</li>
</ul>
</div>
""", 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("""
<div class="platform-card facebook-card">
<h3>π Facebook Extractor</h3>
<ul class="feature-list">
<li>Manual login required</li>
<li>Group post extraction</li>
<li>Works with private groups</li>
<li>AI conversation analysis</li>
<li>100% Free</li>
</ul>
</div>
""", 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("""
<div class="platform-card facebook-pro-card">
<h3>π₯ Facebook Extractor 2.0</h3>
<ul class="feature-list">
<li>Enhanced Facebook data extraction</li>
<li>More powerful algorithms</li>
<li>Faster processing speed</li>
<li>Advanced AI analysis</li>
<li>100% Free</li>
</ul>
</div>
""", 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"""
<a href="{login_url}">
<div style="
background-color: #4285F4;
color: white;
padding: 15px 30px;
border-radius: 8px;
border: none;
cursor: pointer;
font-size: 18px;
font-weight: 600;
text-align: center;
margin: 30px 0;
display: inline-block;
">
<img src="https://cdn-icons-png.flaticon.com/512/2991/2991148.png" width="24" height="24" style="vertical-align: middle; margin-right: 12px;">
Sign in with Google
</div>
</a>
""", 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() |