Download app.py from Refat81/Social_Media_Data_Extractor_Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 7.26 kB
-
https://huggingface.co/spaces/Refat81/Social_Media_Data_Extractor_Chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Refat81/Social_Media_Data_Extractor_Chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Refat81/Social_Media_Data_Extractor_Chatbot/resolve/main/app.py
7.26 kB
| # 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() |